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

AOT breaks window.location

Open saimonsez opened this issue 9 years ago • 2 comments

OS?

Windows 7

Versions.

@angular/cli: 1.0.0-rc.1 node: 6.9.5 os: win32 x64 @angular/common: 2.4.9 @angular/compiler: 2.4.9 @angular/core: 2.4.9 @angular/forms: 2.4.9 @angular/http: 2.4.9 @angular/platform-browser: 2.4.9 @angular/platform-browser-dynamic: 2.4.9 @angular/router: 3.4.9 @angular/cli: 1.0.0-rc.1 @angular/compiler-cli: 2.4.9

Repro steps.

ng build --prod

The log given by the failure.

EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'location' of undefined

Mention any other details that might be useful.

The relevant part of my code: Object.defineProperty(t.prototype, "_APP_CONFIG_94", { get: function() { return null == this.__APP_CONFIG_94 && (this.__APP_CONFIG_94 = { apiEndpoint: et.window.location.origin, // <=== this }), this.__APP_CONFIG_94 }, enumerable: !0, configurable: !0 }),

This happened after updating angular-cli from Beta 26 to RC 1 which enabled AOT by default on prod builds.

My fix for now: Disable AOT with ng build --prod --aot=false

saimonsez avatar Mar 09 '17 08:03 saimonsez

For AOT you should provide window via a factory I think. Either way, this is not a CLI issue but rather a ngc issue. Please check the https://github.com/angular/angular issue tracker.

filipesilva avatar Mar 17 '17 23:03 filipesilva

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.