我需要导入assets
filder中的这个json文件。
{
"HOME": "home"
}
我也在组件中这样做:
import config from "../../../assets/file/config.json";
但是我收到此错误:
Cannot find module '../../..//config.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
所以我以这种方式修改了tsconfig.json
:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": ["es2018", "dom"],
"resolveJsonModule": true,
"esModuleInterop": true
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
但是错误不会消失,它会被抛出相同的错误。有人可以帮助我吗?
文件夹结构为
assets/ file/ and in the /file there is the config.jo;
请尝试以下导入声明:-
[导入*作为来自“ ../../../assets/file/config.json”的配置;
尝试将其直接从资产导入为:
import config from "assets/file/config.json";