问题
I have a basic JSON file in my assets folder of a brand new Angular 10 project.
Angular CLI: 10.0.1
Node: 14.5.0
OS: win32 x64 TSC version 3.9.5.
In my tsconfig.json I have
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true
}
I have restarted vscode multiple times, and tried compiling from the vscode terminal, a powershell window, and a bash terminal, all returning the same message: "Consider using '--resolveJsonModule' to import module with '.json' extension". I have tried compiling with multiple combinations of different options. At this point I'm wondering if I should restart this project and simply downgrade my version of Angular?
回答1:
In Angular version 10 we have 3 "tsconfig" files.
You have to add "resolveJsonModule" and "esModuleInterop" options in the "tsconfig.app.json" file inside the "compilerOptions".
The file should look like this:
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
来源:https://stackoverflow.com/questions/62823189/resolvejsonmodule-not-functioning-with-angular-10