编译 Angular 11(从 Angular 9 升级)应用程序时出错
Posted
技术标签:
【中文标题】编译 Angular 11(从 Angular 9 升级)应用程序时出错【英文标题】:Error in compiling angular 11 (upgraded from angular 9) application 【发布时间】:2021-05-02 05:49:36 【问题描述】:我有一个 Angular 9 应用程序,现在已升级到 Angular 11。 现在在编译 Angular 应用程序时,我遇到了错误。
Compiling @angular/material/core : es2015 as esm2015
Compiling @angular/cdk/scrolling : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Error: Error on worker #2: TypeError: Cannot read property 'map' of null
at ComponentDecoratorHandler.analyze (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\component.js:210:79)
at NgccTraitCompiler.TraitCompiler.analyzeTrait (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:346:40)
at analyze (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:298:58)
at _loop_1 (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:320:21)
at NgccTraitCompiler.TraitCompiler.analyzeClass (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\src\ngtsc\transform\src\compilation.js:326:35)
at NgccTraitCompiler.analyzeFile (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\analysis\ngcc_trait_compiler.js:48:26)
at DecorationAnalyzer.analyzeProgram (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\analysis\decoration_analyzer.js:140:39)
at Transformer.analyzeProgram (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:130:57)
at Transformer.transform (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\packages\transformer.js:76:27)
at C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\execution\create_compile_function.js:49:42
at ClusterMaster.onWorkerMessage (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:195:27)
at C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:55:95
at ClusterMaster.<anonymous> (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:293:57)
at step (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\tslib\tslib.js:143:27)
at Object.next (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\tslib\tslib.js:124:57)
at C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\tslib\tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\tslib\tslib.js:113:16)
at EventEmitter.<anonymous> (C:\Users\RJhaveri\Documents\Ronak\SourceCode\Development\SNSConversionAutomation\sns-conversion\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:287:32)
at EventEmitter.emit (events.js:321:20)
请建议如何解决此问题。
【问题讨论】:
你也升级了棱角材料吗? Angular 建议从 9、10、11 逐步升级。你使用了 Angular 升级 cli 吗? 不,我已将应用程序从 9 升级到 11。我相信这是应用程序无法编译的原因。有什么办法吗? 你是用angular cli升级的吗? 是的,升级是使用 Angular cli 完成的 【参考方案1】:我认为问题是由于应用程序直接从版本 9 升级到版本 11。
最后,我不得不再次移动到 angular 9 版本,然后将其转换为 10。然后从版本 10 到版本 11。现在应用程序运行良好。
【讨论】:
【参考方案2】:请注意要点
请关注guide详细设置link 但在你的情况下
您的旧应用程序存在 aot 错误,并且会出现弃用错误,因此您只需修复它们。
如果仍然遇到任何问题,请在您的项目中 angular.json
"aot":"真"
到
“aot”:“假”
【讨论】:
以上是关于编译 Angular 11(从 Angular 9 升级)应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章
使用 Angular 9 实现 Facebook Pixel
angular 9 库发布错误“尝试发布已由 Ivy 编译的包”