angular: [ng9] Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
š bug report
Affected Package
The issue is caused by package @angular/....Is this a regression?
Yes, the previous version in which this bug was not present was: ng8Description
ng serve is running properly there is no error but sometime we are getting this in web browser console then we need to restart ng serve in order to work again
š¬ Minimal Reproduction
https://stackblitz.com/...š„ Exception or Error
core.js:3866 ERROR Error: Uncaught (in promise): 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.
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:548)
at Function.get (core.js:25892)
at getNgModuleDef (core.js:1865)
at new NgModuleFactory (core.js:24245)
at Compiler_compileModuleSync__POST_R3__ (core.js:27071)
at Compiler_compileModuleAsync__POST_R3__ [as compileModuleAsync] (core.js:27076)
at MergeMapSubscriber.project (router.js:3632)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:61)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (mergeMap.js:51)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)
at resolvePromise (zone.js:836)
at resolvePromise (zone.js:795)
at zone.js:897
at ZoneDelegate.invokeTask (zone.js:431)
at Object.onInvokeTask (core.js:27453)
at ZoneDelegate.invokeTask (zone.js:430)
at Zone.runTask (zone.js:198)
at drainMicroTaskQueue (zone.js:611)
at ZoneTask.invokeTask [as invoke] (zone.js:517)
at invokeTask (zone.js:1671)
š Your Environment
Angular Version:
>ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ ā³ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.0.3
Node: 10.16.0
OS: win32 x64
Angular: 9.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.900.3
@angular-devkit/build-angular 0.900.3
@angular-devkit/build-optimizer 0.900.3
@angular-devkit/build-webpack 0.900.3
@angular-devkit/core 9.0.3
@angular-devkit/schematics 9.0.3
@angular/cdk 8.2.3
@angular/cli 9.0.3
@angular/material 8.2.3
@ngtools/webpack 9.0.3
@schematics/angular 9.0.3
@schematics/update 0.900.3
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 23
- Comments: 66 (15 by maintainers)
Commits related to this issue
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it will be de... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): sniff `main` property for ESM5 format (#36396) Previously, `main` was only checked for `umd` or `commonjs` formats. Now if there are `import` or `export` statements in the source file it w... — committed to angular/angular by petebacondarwin 4 years ago
Also happens here, sometimes. Not 100% yet when exactly but I think when making changes that would need a reload of modules while running ng serve. I.e. when deleting a Component from the declarations array in SharedModuleā¦ this is just a guess. Iāll try to look deeper and update this issue.
Current workaround is to stop ng serve and execute it again. (although this needs a while to compile all the deps as esm5 again)
OK, so I have found the problem and I have a solution.
But first here were my diagnosis steps:
ng serve
I can see thatadal-angular4
is being processedbut I noted that it was compiling the
main
property, which is unusual, as most Angular libraries will provide more modern formats like ES5 or ES2015.When I ran the app, I saw the error reported, so I debugged and stopped on the error. Looking up the call stack I can see that the class trying to be instantiated by the injector is the
AdalService
. Looking at the code for this I see that it has not been modified by ngcc to include the static properties (AdalService.ɵfaca
andAdalService.ɵprov
) that the ivy DI needs.Looking at the
main
entry-point (index.js
) in adal-angular4, I see that it is not formatted as CommonJS but is actually ESM5. Ngcc expects themain
property to point to code that is either CommonJS or UMD. Since this is neither ngcc is not able to process it correctly.So the problem is that adal-angular4 is using the
main
property to point at ESM5 code, which is not strictly correct - or at least is outside of what ngcc can handle, out of the box.The fix is fairly straightforward. We need to teach ngcc that
index.js
is actually an ES5 formatted file. We do this via anngcc.config.js
file at the root of your project, which for this case will look like:What this is saying to ngcc is that the primary entry-point (
"."
) for theadal-angular4
package should have themodule
property in itspackage.json
overridden with the given value ("./index.js"
). In other words, it is like patching thepackage.json
with a new property. After adding this config, ngcc will processindex.js
as ESM5 (which is the format that ngcc expects from themodule
property), and the application will work correctly.This still happens on
9.1.4
this should not be closedHey all. Since this bug was seen by weirdness in my library, I have released adal-angular4 9.0.0-beta0 that provides the correctly formatted package.
I can confirm problem still remains on
version 9.1.4
after runningng build --prod
It helped us turn āoptimizationā into false in angular.json.
I have nowhere near the experience with Angular demonstrated in this thread, however I just experienced this issue when performing the basic Angular TOH app: I went as far as adding the
HeroesComponent
to my template at which point my browser pulled a blank pageāI could access the resources in the dev toolsāand theError: Angular JIT compilation failed: '@angular/compiler' not loaded!
showed in the console. It may be of note that I added the@angular/mamterial
to the project before adding in any code.Based on this thread and on the console suggestion, I added
import "@angular/compiler";
to mymain.ts
and it made my title from myapp-component
show back up in the browser ; but myheroes-component
is still missing from the compiled web page.I couldnāt find the file to edit based on comment 605631297.
Hope this helps to create repro scenarios.
Edit: I removed the
import "@angular/compiler";
line from mymain.ts
and Ctrl+Cāed theng serve --open
. Upon coming back to it for more investigation and relaunching theng server --open
I observed the issue simply went away. Only reason I can think of is that I did all my work with an openng serve
and did not restart it. Iām guessing relaunching the command somehow triggered a reset (?).Yep, the same problem is seen here when updating from 9.0.6 to 9.0.7. Also appears in 9.1.1.
@jrdutton - yes we are going to change the
main
property format sniffing to also look for ESM5 formats (currently it only considers UMD and CommonJS). That should resolve this issue. Not sure of the timeline for this but probably next week sometime.Yep, the same problem is seen here when updating from 9.0.6 to 9.0.7. As above, setting aot to false is a workaround, but is certainly a step backwards.
Also appears in 9.1.0.
Same for us after updating to 9.0.7. Starts working if we set aot: false in angular.json, but that canāt be the fix, can it? Why is it working for us when we do the reverse of PriyaChotiya
Getting this issue. Fine on Angular 9.0.6 but issue appears on 9.0.7 and 9.1.0. Rolling back to 9.0.6, the issue goes away.
Solved in Angular 9.1.11 setting āenableIvyā : false. Tks @miranda-vic and @vt-d-developer
If you are upgrading an Ionic 5 project and getting this error take a look @ https://stackoverflow.com/a/60183174 seems you will need to update some of the ionic-native dependencies to work. One I updated mine this error went away.
@mistic100 - sorry about this. If you are able to, the best approach is to look at the stack trace at the point where this error is thrown. Further up the call-stack you might be able to find a point where it is trying to create a component. This should tell you, at least, which component template contains the offending component that has not been processed by ngcc correctly.
Another approach is to run ngcc across the whole node_modules directly with debug logging and see if there are any useful messages. Run
node_modules/.bin/ngcc -l debug
.For people still seeing this issue: it is typically caused by one of these reasons:
For the first case, please try to figure out what library is a problem, then seeing if an updade is available or whether thereās an open issue with that library. If you canāt find any of that, please open a new issue here with a reproduction repo, preferably using a minimal Github repro.
@JulioBastidas ngcc should automatically pick up that file if it exists.