Angular-cli: v1.5.1 AOT Build - Uncaught ReferenceError: InjectionToken is not defined

Created on 16 Nov 2017  路  9Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 1.5.1
Node: 8.6.0
OS: win32 x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

@angular/cli: 1.5.1
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.1
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • ng serve --aot

Observed behavior

Uncaught ReferenceError: InjectionToken is not defined
    at eval (logger.service.ts:20)
    at Object.../../../../../src/app/shared/services/logger/logger.service.ts (main.bundle.js:206)
    at __webpack_require__ (inline.bundle.js:713)
    at fn (inline.bundle.js:118)
    at eval (logger.module.ts:2)
    at Object.../../../../../src/app/shared/services/logger/logger.module.ts (main.bundle.js:198)
    at __webpack_require__ (inline.bundle.js:713)
    at fn (inline.bundle.js:118)
    at eval (index.ts:1)
    at Object.../../../../../src/app/shared/services/index.ts (main.bundle.js:190)

Desired behavior


The app builds fine in AOT mode with no error, but when I run it in the browser, it results in the error provided above during bootstrap process. I tried to reproduce this error on CLI 1.5.0 and it works fine. It complains about InjectionToken being not defined.

Mention any other details that might be useful (optional)

Only happening on v1.5.1, works on v1.5.0. No other dependency was changed. All I did was upgrade @angular/cli from 1.5.0 to 1.5.1.

Most helpful comment

We're investigating. If we haven't found a root cause in 15-30 minutes after this message we'll revert the PR and do an emergency release.

All 9 comments

I have a similar issue. My app worked fine with 5.0.1 and CLI 1.5.0. Once I upgraded to 1.5.1, the app fails to load properly and the first error I get is from one of my components: ReferenceError: EventEmitter is not defined ReferenceError: EventEmitter is not defined

The offending line of code is a declaration of a property of my component before the constructor:

@Output() notify: EventEmitter<string> = new EventEmitter<string>();

Moving this initialization to the constructor didn't help. My app works fine with a JIT build, but breaks once AOT is involved.

Same here. I'm getting Uncaught ReferenceError: Optional is not defined with AOT build after upgrading to 1.5.1.

Code that causes the error:

// some code....
import { Inject, Injectable, Optional, Renderer, SkipSelf, InjectionToken } from '@angular/core';
// some code....
export const CLIPBOARD_SERVICE_PROVIDER = {
    provide: ClipboardService,
    deps: [DOCUMENT, WINDOW, [
        new Optional(), // -<<< error
        new SkipSelf(),
        ClipboardService
    ]],
    useFactory: CLIPBOARD_SERVICE_PROVIDER_FACTORY
};
// some code....

I'm having the same issue as @bomberblue07. Even just private emitter = new EventEmitter(); breaks when using AOT.

Confirmed that @angular/cli 1.5.1 seems to be the issue

Works with --prod on 1.5.0

onMaximize = new EventEmitter<void>();

Fails with --prod on 1.5.1

ReferenceError: EventEmitter is not defined

Confirmed same issus at @angular/cli 1.5.1 when launching the app:

ng build --prod

main.d559f48d0942eebadd8a.bundle.js:1 ERROR ReferenceError: EventEmitter is not defined
at new e (main.d559f48d0942eebadd8a.bundle.js:1)
at jt (main.d559f48d0942eebadd8a.bundle.js:1)
at Vt (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at En (main.d559f48d0942eebadd8a.bundle.js:1)
at _n (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at un (main.d559f48d0942eebadd8a.bundle.js:1)
at Object.createRootView (main.d559f48d0942eebadd8a.bundle.js:1)
at t.create (main.d559f48d0942eebadd8a.bundle.js:1)
(anonymous) @ main.d559f48d0942eebadd8a.bundle.js:1
main.d559f48d0942eebadd8a.bundle.js:1 ERROR Error: Uncaught (in promise): ReferenceError: EventEmitter is not defined
ReferenceError: EventEmitter is not defined
at new e (main.d559f48d0942eebadd8a.bundle.js:1)
at jt (main.d559f48d0942eebadd8a.bundle.js:1)
at Vt (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at En (main.d559f48d0942eebadd8a.bundle.js:1)
at _n (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at un (main.d559f48d0942eebadd8a.bundle.js:1)
at Object.createRootView (main.d559f48d0942eebadd8a.bundle.js:1)
at t.create (main.d559f48d0942eebadd8a.bundle.js:1)
at new e (main.d559f48d0942eebadd8a.bundle.js:1)
at jt (main.d559f48d0942eebadd8a.bundle.js:1)
at Vt (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at En (main.d559f48d0942eebadd8a.bundle.js:1)
at _n (main.d559f48d0942eebadd8a.bundle.js:1)
at fn (main.d559f48d0942eebadd8a.bundle.js:1)
at un (main.d559f48d0942eebadd8a.bundle.js:1)
at Object.createRootView (main.d559f48d0942eebadd8a.bundle.js:1)
at t.create (main.d559f48d0942eebadd8a.bundle.js:1)
at i (polyfills.a1ece476dc448026a76f.bundle.js:1)
at polyfills.a1ece476dc448026a76f.bundle.js:1
at t.invokeTask (polyfills.a1ece476dc448026a76f.bundle.js:1)
at Object.onInvokeTask (main.d559f48d0942eebadd8a.bundle.js:1)
at t.invokeTask (polyfills.a1ece476dc448026a76f.bundle.js:1)
at r.runTask (polyfills.a1ece476dc448026a76f.bundle.js:1)
at o (polyfills.a1ece476dc448026a76f.bundle.js:1)
at
(anonymous) @ main.d559f48d0942eebadd8a.bundle.js:1

We're investigating. If we haven't found a root cause in 15-30 minutes after this message we'll revert the PR and do an emergency release.

I reverted the latest dist-tag to 1.5.0. You can probably just reinstall your project and be good. We're going to be investigating.

@hansl Thanks for the quick response and fix. Much appreciated 馃憤

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

Was this page helpful?
0 / 5 - 0 ratings