简体   繁体   English

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

[英]Angular JIT compilation failed: '@angular/compiler' not loaded

Angular JIT compilation failed: '@angular/compiler' not loaded! Angular JIT 编译失败:'@angular/compiler' 未加载!

  • JIT compilation is discouraged for production use-cases!不鼓励对生产用例进行 JIT 编译! Consider AOT mode instead.请考虑使用 AOT 模式。
  • Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?您是否使用“@angular/platform-b​​rowser-dynamic”或“@angular/platform-server”进行引导?
  • Alternatively provide the compiler with 'import "@angular/compiler";'或者为编译器提供 'import "@angular/compiler";' before bootstrapping.在引导之前。

Getting this error when build production build in dev mode not getting any error在开发模式下构建生产构建时出现此错误没有收到任何错误

You could try any of the following solutions:您可以尝试以下任何一种解决方案:

Solution 1解决方案 1

Run the following command to update all dependencies as their might have some incompatibilities:运行以下命令来更新所有依赖项,因为它们可能有一些不兼容:

npm update

Solution 2解决方案 2

Make sure you have already imported '@angular/compiler' at the very top of your main.ts file.确保您已经在main.ts文件的最顶部导入了'@angular/compiler'

Now set the following line现在设置以下行

aot=true 

in angular.json file.angular.json文件中。

Also, set the following line另外,设置以下行

scripts{
  "postinstall": "ngcc --properties es2015 browser module main --first- only --create-ivy-entry-points"
}

in package.json file and then delete node_modules folder and package-lock.json file and then run the following command:package.json文件中,然后删除node_modules文件夹和package-lock.json文件,然后运行以下命令:

npm install

Solution 3解决方案 3

Disable Ivy engine in tsconfig.json file:tsconfig.json文件中禁用 Ivy 引擎:

"angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true, "enableIvy": false }

Late to answer this, but since this came up first on Google Search results, my fix could be helpful to someone else (might even help me in future ;) ).回答这个问题很晚,但由于这首先出现在 Google 搜索结果中,因此我的修复可能对其他人有所帮助(将来甚至可能对我有所帮助;))。

If your app is using HttpClient for making any HTTP calls, probably you did similar mistake as me and imported HttpClient instead of HttpClientModule & ended up with the error message from question.如果您的应用程序使用HttpClient进行任何 HTTP 调用,则可能您犯了与我类似的错误并导入HttpClient而不是HttpClientModule并最终得到来自问题的错误消息。

Simply replace the HttpClient with HttpClientModule in your imports array in @NgModule & add import the class.只需在@NgModuleimports数组中将HttpClientModule替换为HttpClient并添加导入类。

import { HttpClientModule } from '@angular/common/http';

@NgModule({
    declarations: [AppComponent, ProductListComponent],
    imports: [BrowserModule, FormsModule, HttpClientModule],
    bootstrap: [AppComponent],
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 Angular 9 的 Ionic 5 - Angular JIT 编译失败:“@angular/compiler”未加载 - Ionic 5 with Angular 9 - Angular JIT compilation failed: '@angular/compiler' not loaded 未捕获错误:Angular JIT 编译失败:'@angular/compiler' 未加载 - Uncaught Error: Angular JIT compilation failed: '@angular/compiler' not loaded ERROR 错误:Angular JIT 编译失败:'@angular/compiler' 未加载 - ERROR Error: Angular JIT compilation failed: '@angular/compiler' not loaded 空白屏幕 - Angular JIT 编译失败:'@angular/compiler' 未加载 - Blank Screen - Angular JIT compilation failed: '@angular/compiler' not loaded 未捕获(承诺):错误:Angular JIT 编译失败:'@angular/compiler' 未加载! 在 angular 9 - Uncaught (in promise): Error: Angular JIT compilation failed: '@angular/compiler' not loaded! in angular 9 Angular 9 未处理的 Promise 拒绝:Angular JIT 编译失败错误 - Angular 9 Unhandled Promise rejection: Angular JIT compilation failed error 为什么Angular 2的模板具有JiT编译功能? - Why does Angular 2 have JiT compilation for templates? Angular 5的默认编译是什么? (AOT或JIT) - What is the default compilation for Angular 5? (AOT or JIT) 错误:执行 AngularJS 到 Angular 13 迁移时,JIT 编译因可注入 class PlatformLocation {} 失败 - Error:JIT compilation failed for injectable class PlatformLocation {} while doing AngularJS to Angular 13 migration Angular AOT和JIT编译器有什么区别 - What is the difference between Angular AOT and JIT compiler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM