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

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

Open distributedlock opened this issue 9 years ago • 9 comments

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.

distributedlock avatar Nov 16 '17 21:11 distributedlock

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.

bomberblue07 avatar Nov 16 '17 21:11 bomberblue07

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

ghost avatar Nov 16 '17 21:11 ghost

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

briandemaio avatar Nov 16 '17 22:11 briandemaio

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

drewgreenwell avatar Nov 16 '17 22:11 drewgreenwell

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

sgomanf avatar Nov 16 '17 23:11 sgomanf

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.

hansl avatar Nov 16 '17 23:11 hansl

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 avatar Nov 16 '17 23:11 hansl

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

distributedlock avatar Nov 17 '17 00:11 distributedlock

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.