angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open JonWallsten opened this issue 6 years ago • 48 comments

🐞 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)

  • [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 ()
    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?

JonWallsten avatar Feb 07 '20 11:02 JonWallsten

Have you tried running ngcc directly over the whole of node_modules? You might get some useful warnings about some of the entry-points. E.g. ngcc -l debug

petebacondarwin avatar Mar 18 '20 10:03 petebacondarwin

I'm getting this issue but only after upgrading from angular 9.0.6 to 9.0.7, if I revert the issue goes away.

JACrazy avatar Mar 20 '20 01:03 JACrazy

Same here, no other changes made.

submarines-and avatar Mar 20 '20 06:03 submarines-and

In my case I've just reload application and all works.

varanakonda avatar Mar 27 '20 17:03 varanakonda

In my case I've just reload application and all works.

Thanks. Indeed by AOT being default with angular 9, you cannot change dependencies while serving.

Frotty avatar Mar 30 '20 12:03 Frotty

I am facing the the following issues when i try to do 'ng serve' after upgrading to 9.0.7.

NG8001: 'mat-select' is not a known element:

  1. If 'mat-select' is an Angular component and it has 'disabled' input, then verify that it is part of this module.
  2. If 'mat-select' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
  3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

error NG8001: 'mat-form-field' is not a known element:

  1. If 'mat-form-field' is an Angular component, then verify that it is part of this module.
  2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'. <input matInput #input class="form-control" placeholder="XXX" [(ngModel)]="XX.yy"

If i update aot:false ng serve is working fine , but on building for prod i', again facing the above mentioned issues.

Everything was working completely fine with 9.0.6. Could some body help me out?

My Package File:

{ "name": "nol-ui", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~9.0.7", "@angular/cdk": "~9.2.0", "@angular/common": "~9.0.7", "@angular/compiler": "~9.0.7", "@angular/core": "~9.0.7", "@angular/forms": "~9.0.7", "@angular/material": "^9.2.0", "@angular/platform-browser": "~9.0.7", "@angular/platform-browser-dynamic": "~9.0.7", "@angular/router": "~9.0.7", "classlist.js": "^1.1.20150312", "handlebars": "^4.7.3", "kind-of": "^6.0.3", "lodash": "^4.17.15", "rxjs": "~6.5.4", "serialize-javascript": "^2.1.2", "tree-kill": "^1.2.2", "tslib": "^1.10.0", "web-animations-js": "^2.3.2", "zone.js": "~0.10.2" }, "devDependencies": { "@angular-devkit/build-angular": "~0.900.7", "@angular/cli": "~9.0.7", "@angular/compiler-cli": "~9.0.7", "@angular/language-service": "~9.0.7", "@types/jasmine": "^3.3.16", "@types/jasminewd2": "^2.0.8", "@types/node": "^12.12.34", "codelyzer": "^5.1.2", "jasmine-core": "~3.4.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.1.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "^2.0.6", "karma-jasmine": "~2.0.1", "karma-jasmine-html-reporter": "^1.5.3", "protractor": "^5.4.3", "ts-node": "~7.0.0", "tslint": "~5.15.0", "typescript": "~3.7.5" } }

sampath0606 avatar Mar 31 '20 13:03 sampath0606

Anyone with this issue after 9.0.7 see this thread https://github.com/angular/angular/issues/35788#issuecomment-606455043

There's a workaround fix commented, but they also said they'll look into having an update probably next week that will help support packages with ESM5 format.

JACrazy avatar Apr 01 '20 15:04 JACrazy

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.