Uncaught Error: Angular JIT compilation failed: '@angular/compiler' not loaded!

See original GitHub issue

🐞 Bug report

This is probably a feature and not a bug. But I can’t find any useful information on how to fix it. I get no relevant hits on the error message itself, so I guess it’s fairly new ur really uncommon.

Command (mark with an x)

  • build

Is this a regression?

Yes, the previous version in which this bug was not present was: 9.0.0-rc.7

Description

A clear and concise description of the problem...

I’m building my app with Webpack and AngularCompilerPlugin. After compilation is done and I load the URL where the app is served I’m met with blank page the the following error:

Uncaught 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.

I’ve been using this code since Angular 5 or 6. So I have never been forced to understand what it actually does. Since I’m building with AngularCompilerPlugin it is to my understanding AOT and not JIT. So what does “Consider AOT mode instead.” mean in this case?

🔬 Minimal Reproduction

Since this is not an open source project it would take a lot of time to create a repro. I will gladly do this if it cannot be solved any other way. Just let me know.

main.ts

platformBrowserDynamic().bootstrapModule(AppModule)
    .then(module => {
        if (!environment.production) {
            const applicationRef = module.injector.get(ApplicationRef);
            const appComponent = applicationRef.components[0];
            enableDebugTools(appComponent);
        }
    })
    .catch(err => console.error(err));

webpack.config.ts

new AngularCompilerPlugin({
    tsConfigPath: helpers.rootPath('tsconfig.build.json'),
    mainPath: helpers.rootPath('src/main.ts'),
    sourceMap: true
}),

🔥 Exception or Error


angular.js:24565 Uncaught 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 (angular.js:24565)
    at Function.get (angular.js:49779)
    at registerNgModuleType (angular.js:48055)
    at angular.js:48066
    at Array.forEach (<anonymous>)
    at registerNgModuleType (angular.js:48066)
    at new NgModuleFactory (angular.js:48173)
    at compileNgModuleFactory__POST_R3__ (angular.js:51698)
    at PlatformRef.push.../../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.PlatformRef.bootstrapModule (angular.js:51921)
    at eval (main.ts:19)

🌍 Your Environment


Angular CLI: 9.0.1
Node: 12.14.0
OS: win32 x64

Angular: 9.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.1
@angular-devkit/build-optimizer   0.900.1
@angular-devkit/core              9.0.1
@angular-devkit/schematics        9.0.1
@angular/cli                      9.0.1
@angular/http                     8.0.0-beta.10
@ngtools/webpack                  9.0.1
@schematics/angular               9.0.1
@schematics/update                0.900.1
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.5

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:48 (17 by maintainers)

github_iconTop GitHub Comments

4reactions
speedy32commented, Feb 20, 2020

In my case I had this kind of problem because someone in project did reference to Injectable like below: import { Injectable } from ‘…/…/…/…/…/…/node_modules/@angular/core’;

3reactions
JonWallstencommented, Feb 7, 2020

Can you try including both es2015 and es5? I suspect that you have some packages that only have one or the other. So by not including them both, you end up with at least one unprocessed package.

I did run them one after the other, so they should both be there. I just got home. But I’ll answer any questions you have about the repro incase you get into any trouble. It’s a bit complex setup due to legacy stuff.

I added import '@angular/compiler'; in main.ts in-case you want to remove it and investigate the JIT-error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise): Error: Angular JIT compilation failed
I had similar error using angular 12: The injectable needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
Read more >
How to fix Uncaught (in promise): Error: Angular JIT ...
How to fix Uncaught (in promise): Error: Angular JIT compilation failed: '@angular/compiler' not loaded! This error can occur in Angular and is actually ......
Read more >
Might not be an Ionic issue but...Angular JIT compilation failed
I'm a little green to Ionic/Angular and am not entirely sure where the dividing line between the two is so… Angular CLI: 9.1.2...
Read more >
JIT compilation failed for NgModule class AppModule - YouTube
... Uncaught Error : The NgModule 'AppModule' needs to be compiled using the JIT compiler, but '@ angular / compiler ' is not...
Read more >
angular/angular - Gitter
Uncaught Error : Angular JIT compilation failed: '@angular/compiler' not loaded! do we have to explicitly add @angular/compiler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found