Angular 9未处理的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

我在main.ts文件的顶部添加了import"@angular/compiler,但运气不好。

除了zone.js,我还删除了polyfill中的所有导入,但仍然收到错误。

这意味着什么?如何解决?

您需要在main.ts文件的顶部导入'@angular/compiler',但由于您已经有了它,因此

你必须在你的包中运行这个.json

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

最新更新