I am trying to build a project where I have one json file that I have to parse in my main file. But I cannot include it in main file. In terminal there is no error both for main.ts and main.js. Webview panel is showing the content from the html but nothing from the main file. If I inspect through developer tools, it's displaying error. I am importing json in main.ts and the main.js is the compiled file for main.ts. I need both the files and the error is occurring for either of them.
I have tried different combinations
Combination 1:
import json from "./test.json"; //in main.ts file
"module": "commonjs" // in tsconfig.json file
Error is "exports is not defined at main.js file"
Combination 2:
const json = require("./test.json"); //in main.ts file
"module": "commonjs" // in tsconfig.json file
Error is "require is not defined at main.ts"
Combination 3:
const json = require("./test.json"); //in main.ts file
"module": "es2015" // in tsconfig.json file
Error is "require is not defined at main.ts"
Combination 4:
import json from "./test.json"; //in main.ts file
"module": "es2015" // in tsconfig.json file
Error is "Cannot use import statement outside a module"
And below is an example of my complete tsconfig.json
{
"compilerOptions": {
"module": "es2015",
"target": "es5",
"outDir": "out",
"sourceMap": true,
"strict": true,
"rootDir": "src",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"strictNullChecks":false,
"lib": ["dom","es2015","es5","es6"]
},
"exclude": ["node_modules", ".vscode-test"],
"include" : [
"src/**/*"
]
}
What am I doing wrong? Please help. Thanks in advance.