[英]Angular JIT compilation failed: '@angular/compiler' not loaded
Angular JIT compilation failed: '@angular/compiler' not loaded! Angular JIT 编译失败:'@angular/compiler' 未加载!
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.只需在@NgModule
的imports
数组中将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.