I have tried every solution found online but it seems I cannot get my specifics resolved.
I am trying to import a static .json file into a node controller, all in TypeScript.
The error I'm getting is
Cannot find module './data.map.json'
I've checked the path 100 times it's definitely correct. I have tried every combination of require vs import, and every option I could find in tsconfig.json, which is where I believe the problem lies.
Below is a clean minimal example showing my setup. How can I import a static json file in my Typescript application?
controller
import * as data from "./data.map.json";
typings.d.ts
declare module "*.json" {
const value: any;
export default value;
}
tsconfig.json
{
"compilerOptions": {
"outDir": "build",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"typeRoots": ["node_modules/@types"],
"paths": {
"*": ["typings.d.ts"]
}
},
"files": [
"typings.d.ts"
],
"include": [
"src/**/**.ts",
"test/**/**.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false
}