-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.4.5
node: 6.9.5
os: win32 x64
@angular/animations: 4.4.6
@angular/cdk: 2.0.0-beta.12
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/material: 2.0.0-beta.12
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.5
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4
Repro steps.
build with --prod
ng build --prod
main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import {hmrBootstrap} from "./hmr";
if (environment.production) {
enableProdMode();
}
const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule);
if (environment.hmr) {
if (module[ 'hot' ]) {
hmrBootstrap(module, bootstrap);
} else {
console.error('HMR is not enabled for webpack-dev-server!');
}
} else {
bootstrap();
}
I have not use isDevMode()。
The log given by the failure.
open the page in the chrome,console print error:
vendor.9844cf9b240425f86ca5.bundle.js:1 Uncaught Error: Cannot enable prod mode after platform setup.
at ot (vendor.9844cf9b240425f86ca5.bundle.js:1)
at Object.cDNt (main.fd315af370796125e230.bundle.js:1)
at n (inline.0a6d3c44cde3756d710d.bundle.js:1)
at Object.0 (main.fd315af370796125e230.bundle.js:1)
at n (inline.0a6d3c44cde3756d710d.bundle.js:1)
at window.webpackJsonp (inline.0a6d3c44cde3756d710d.bundle.js:1)
at main.fd315af370796125e230.bundle.js:1
Desired functionality.
enable prod mode.
Mention any other details that might be useful.
build without --target=production
ng build --environment=prod
the relative part in vendor.js
var _devMode = true;
var _runModeLocked = false;
var _platform;
var ALLOW_MULTIPLE_PLATFORMS = new InjectionToken('AllowMultipleToken');
function enableProdMode() {
if (_runModeLocked) {
throw new Error('Cannot enable prod mode after platform setup.');
}
_devMode = false;
}
function isDevMode() {
_runModeLocked = true;
return _devMode;
}
variable _runModeLocked initiate false。it changes to true when we call isDevMode().
build with --target=production
ng build --prod
the relative part in vendor.js
function ot() { if (No) throw new Error("Cannot enable prod mode after platform setup.");
Ro = !1 }
function st() { return No = !0, Ro }
No = !1,
Ro = function(t) {
function e(e, n, r, i, o) { t.call(this), this.initialState = e, this.condition = n, this.iterate = r, this.resultSelector = i, this.scheduler = o } return jo(e, t), e.create = function(t, n, r, i, o) { return 1 == arguments.length ? new e(t.initialState, t.condition, t.iterate, t.resultSelector || Io, t.scheduler) : void 0 === i || g(i) ? new e(t, n, r, Io, i) : new e(t, n, r, i, o) }, e.prototype._subscribe = function(t) { var n = this.initialState; if (this.scheduler) return this.scheduler.schedule(e.dispatch, 0, { subscriber: t, iterate: this.iterate, condition: this.condition, resultSelector: this.resultSelector, state: n }); for (var r = this, i = r.condition, o = r.resultSelector, s = r.iterate;;) { if (i) { var a = void 0; try { a = i(n) } catch (e) { return void t.error(e) } if (!a) { t.complete(); break } } var u = void 0; try { u = o(n) } catch (e) { return void t.error(e) } if (t.next(u), t.closed) break; try { n = s(n) } catch (e) { return void t.error(e) } } }, e.dispatch = function(t) { var e = t.subscriber,
n = t.condition; if (!e.closed) { if (t.needIterate) try { t.state = t.iterate(t.state) } catch (t) { return void e.error(t) } else t.needIterate = !0; if (n) { var r = void 0; try { r = n(t.state) } catch (t) { return void e.error(t) } if (!r) return void e.complete(); if (e.closed) return } var i; try { i = t.resultSelector(t.state) } catch (t) { return void e.error(t) } if (!e.closed && (e.next(i), !e.closed)) return this.schedule(t) } }, e }(fi),
No = Ro.create;
the variable No initiate !1(false),then reassign RO.create.
I don't clear whether if RO.create change the No value to true.