问题
Ionic 5 was announced a few hours ago (12th Feb 2020) and I upgraded my one of the small production app to Ionic 5 along with Angular 9:
# To update to Ionic 5
npm install @ionic/angular@latest @ionic/angular-toolkit@latest --save-exact --save
# To update to Angular 9
ng update @angular/core @angular/cli
But when I did ionic serve
, I started getting the bellow error:
Error: 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.
at getCompilerFacade (core.js:610)
at Function.get (core.js:16065)
at getInjectableDef (core.js:362)
at injectableDefOrInjectorDefFactory (core.js:16816)
I came across a few Angular GitHub issues:
- https://github.com/angular/angular-cli/issues/16873
- https://github.com/angular/angular/issues/32466
They are saying to include import '@angular/compiler';
in main.ts
file but when I matched one of my other Angular 9 application (which I updated recently), I don't see such configurations there.
Is Angular 9 not compatible with Ionic 5?
回答1:
For me, two solutions worked. Not sure if they are perfect.
Solution 1 (I feel, this is recommended)
Wat to add import '@angular/compiler';
in main.ts
file.
Solution 2
Was to turn off the AOT by changing "aot": true
to "aot: false
in angular.json
file. I would not recommend this as this improves the performance of the Angular app.
回答2:
Try ng serve --aot
, it helped me fix the problem, that's if you want to run with aot which is recommended since it will be similar to the production build and it will help you catch errors sooner.
Hope this helps.
Angular Link: https://angular.io/guide/aot-compiler
来源:https://stackoverflow.com/questions/60183056/ionic-5-with-angular-9-angular-jit-compilation-failed-angular-compiler-not