Angular JIT compilation failed: '@angular/compiler' not loaded
Asked Answered
S

2

3

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.

Getting this error when build production build in dev mode not getting any error

Stockade answered 7/9, 2021 at 6:43 Comment(4)
Does this answer your question? Ionic 5 with Angular 9 - Angular JIT compilation failed: '@angular/compiler' not loadedBackdate
That all solution not work for meStockade
Re-creating android platform fixed the issue for me. Check out: blank-screen-angular-jit-compilation-failed-angular-compiler-not-loadedMunificent
Re-creating android platform fixed the issue for me. Check out: enter link description hereMunificent
C
2

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 ;) ).

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.

Simply replace the HttpClient with HttpClientModule in your imports array in @NgModule & add import the class.

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

@NgModule({
    declarations: [AppComponent, ProductListComponent],
    imports: [BrowserModule, FormsModule, HttpClientModule],
    bootstrap: [AppComponent],
})
Cachet answered 20/6, 2022 at 19:14 Comment(0)
L
8

You could try any of the following solutions:

Solution 1

Run the following command to update all dependencies as their might have some incompatibilities:

npm update

Solution 2

Make sure you have already imported '@angular/compiler' at the very top of your main.ts file.

Now set the following line

aot=true 

in angular.json file.

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:

npm install

Solution 3

Disable Ivy engine in tsconfig.json file:

"angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true, "enableIvy": false }
Lurk answered 7/9, 2021 at 9:30 Comment(0)
C
2

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 ;) ).

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.

Simply replace the HttpClient with HttpClientModule in your imports array in @NgModule & add import the class.

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

@NgModule({
    declarations: [AppComponent, ProductListComponent],
    imports: [BrowserModule, FormsModule, HttpClientModule],
    bootstrap: [AppComponent],
})
Cachet answered 20/6, 2022 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.