【发布时间】:2021-01-30 04:42:48
【问题描述】:
我在浏览器中收到Cannot access 'MyComponent' before initialization 错误消息。
ng build 运行没有错误。
我对此主题进行了一些研究,并找到了使用此设置更新我的应用程序的 tsconfig.base.json 文件的建议:
{
"compilerOptions": {
"emitDecoratorMetadata": false
}
}
这没有帮助。所以添加了这个:
"annotateForClosureCompiler": {
"annotateForClosureCompiler": true
}
也没有帮助。因此尝试将target 从es2015 更改为任何新的但未解决问题。
我也尝试在我的库中更改这些设置(包含组件的内容),但没有帮助。
我检查了这些讨论:
- Same issue in Angular 7.2.1
- Next question from Oliver Matrot
- Property decorators break at runtime with ES2015 and circular deps on GitHub angular/angular
- ES2015 + emitDecoratorMetadata causes Cannot access before intialization on GitHub angular/angular-cli
在我的例子中,我使用来自 Angular 包的10.1.6:
{
"dependencies": {
"@angular/animations": "^10.1.6",
"@angular/cdk": "^10.2.5",
"@angular/common": "^10.1.6",
"@angular/compiler": "^10.1.6",
"@angular/core": "^10.1.6",
"@angular/forms": "^10.1.6",
"@angular/material": "^10.2.5",
"@angular/platform-browser": "^10.1.6",
"@angular/platform-browser-dynamic": "^10.1.6",
"@angular/router": "^10.1.6",
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.1001.3",
"@angular/cli": "^10.1.7",
"@angular/compiler-cli": "^10.1.6",
}
}
有什么想法吗?
【问题讨论】:
标签: angular angular-library angular10