我有一个src/assets/version.json
包含以下内容的 json 文件:
{"VERSION":"1.0.0"}
我将文件导入到*.ts
,例如:
import * as VersionInfo from 'src/assets/version.json';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
console.log(`version ${VersionInfo['VERSION']}`);
}
}
输出
version 1.0.0
这适用于 Angular 11,但在 Angular 12 上,CLI 显示错误
Should not import the named export 'VERSION' (imported as 'VersionInfo') from default-exporting module (only default export is available soon)
这是我的 tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"strictPropertyInitialization": false,
"baseUrl": "./",
"importHelpers": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"target": "es2015",
"resolveJsonModule": true,
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"jszip": [
"node_modules/jszip/dist/jszip.min.js"
]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"strictInjectionParameters": true
},
}
如何修复此错误?