angular-cli: ng build --prod fails with "o.JitCompilerFactory is not a constructor"

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request


Angular CLI: 1.5.0
Node: 6.10.0
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack: 3.8.1

Repro steps.

Just switched to version 1.5 with Angular 5 while trying to rebuild the app, trying to run ng build --prod. The build itself works fine, no error occurs in the cli, just the produced output is not working in the browser anymore. Here’s the build output (with build-optimizer enabled)

$ ng build --prod
Time: 122549ms
chunk {0} polyfills.5be7b4440c7063a52728.bundle.js (polyfills) 65.8 kB [initial] [rendered]
chunk {1} main.0b8a07797f45da90c346.bundle.js (main) 1.59 MB [initial] [rendered]
chunk {2} styles.81bdc1589614d677343f.bundle.css (styles) 222 kB [initial] [rendered]
chunk {3} inline.022aa018a8a39e60af21.bundle.js (inline) 1.45 kB [entry] [rendered]

I also tried removing the build-optimizer ng build --prod --build-optimizer false, still the same problem in the browser. If I don’t build it with the --prod flag, everything is working fine. So I guess this has something to do with the --prod flag.

The log given by the failure.

Here’s what the browser tells me directly on loading the page.

Uncaught TypeError: o.JitCompilerFactory is not a constructor
    at l (main.0b8a07797f45da90c346.bundle.js:1)
    at Je (main.0b8a07797f45da90c346.bundle.js:1)
    at Ye (main.0b8a07797f45da90c346.bundle.js:1)
    at Ze (main.0b8a07797f45da90c346.bundle.js:1)
    at new t (main.0b8a07797f45da90c346.bundle.js:1)
    at Object._n [as createNgModuleRef] (main.0b8a07797f45da90c346.bundle.js:1)
    at e.create (main.0b8a07797f45da90c346.bundle.js:1)
    at main.0b8a07797f45da90c346.bundle.js:1
    at e.invoke (polyfills.5be7b4440c7063a52728.bundle.js:1)
    at Object.onInvoke (main.0b8a07797f45da90c346.bundle.js:1)

Desired functionality.

Production build app working in the browser again.

Mention any other details that might be useful.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20

Most upvoted comments

Yeah it seems that some errors only occur when build with aot which unfortunately means the code is minified and uglified and whatsoever, but in dev build everything works fine, this can be nerve wrecking.

But I’m glad you found what was messing up your build =) this may also be useful for others having a similar problem.