首页 > 解决方案 > Angular 9 Unhandled Promise 拒绝:Angular JIT 编译失败错误

问题描述

我将我们的应用程序升级到 Angular 9,但在生产测试中我收到了这个错误。ng serve --optimization=true --aot=true --prod在将其部署到生产之前,我正在使用命令为我的应用程序提供服务,但它只是无法正常工作

Unhandled Promise rejection: Angular JIT compilation failed: '@angular/compiler' not loaded!
  - JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
  - Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
  - Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping. ; Zone: <root> ;

这是指向我的 polyfills.ts

我已将 import "@angular/compiler 添加到我的 main.ts 文件的顶部,但没有成功。

除了 zone.js 之外,我还从 polyfill 中删除了所有导入,但仍然出现错误。

这是什么意思,如何解决?

标签: angular

解决方案


您需要在 main.ts 文件的最顶部导入“@angular/compiler”,但既然您已经拥有它,那么

你必须在你的 package.json 中运行它

scripts{
"postinstall": "ngcc --properties es5 browser module main --first-only"
}

推荐阅读