Angular JIT 编译失败:“@angular/compiler”未加载

siv*_*ivu 3 angular-material angular ionic5

Angular JIT 编译失败:“@angular/compiler”未加载!

  • 对于生产用例,不鼓励使用 JIT 编译!请考虑使用 AOT 模式。
  • 您是否使用“@angular/platform-b​​rowser-dynamic”或“@angular/platform-server”进行引导?
  • 或者为编译器提供 'import "@angular/compiler";' 在引导之前。

在开发模式下构建生产构建时出现此错误,但没有出现任何错误

Sal*_*med 8

您可以尝试以下任一解决方案:

解决方案1

运行以下命令来更新所有依赖项,因为它们可能存在一些不兼容性:

npm update
Run Code Online (Sandbox Code Playgroud)

解决方案2

确保您已'@angular/compiler'在文件的最顶部导入main.ts

现在设置以下行

aot=true 
Run Code Online (Sandbox Code Playgroud)

angular.json文件中。

另外,设置以下行

scripts{
  "postinstall": "ngcc --properties es2015 browser module main --first- only --create-ivy-entry-points"
}
Run Code Online (Sandbox Code Playgroud)

文件package.json,然后删除node_modules文件夹和package-lock.json文件,然后运行以下命令:

npm install
Run Code Online (Sandbox Code Playgroud)

解决方案3

在文件中禁用 Ivy 引擎tsconfig.json

"angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true, "enableIvy": false }
Run Code Online (Sandbox Code Playgroud)