question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught Error: Cannot enable prod mode after platform setup.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
bananercommented, Dec 8, 2017

I think it should be made clear that isDevMode() should only be called after enableProdMode() was called.

@sataqi since you are saving the value as a global constant here, it will be called before you call enableProdMode() in main.ts.

There is very little overhead to just calling isDevMode() every time from inside your components, e.g. here, and that should make it work.

5reactions
filipesilvacommented, Jan 9, 2018

Like @bananer mentioned, you cannot call isDevMode() before enableProdMode() is called. The error shown is expected behaviour.

Closing as answered by @bananer.

@Tooluloope you should search your code for calls to isDevMode. If it is not in your code, it might be in a library. If you can provide a reproduction we might be able to investigate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot enable prod mode after platform setup. Angular 5 ...
I have found this error When I use the function isDevMode() in the app.module and ...
Read more >
Cannot enable prod mode after platform setup. Angular 5 ...
in file cli-reproapp/src/app/app.constants.ts . So as a workaround you can create a function instead of constant isInDevMode as is shown below.
Read more >
Angular (forked) - StackBlitz
if you get 'Cannot enable production mode'. error, please reopen the preview window as. explained here ... 47983242/cannot-enable-prod-mode-after-setup.
Read more >
How to add address detail in the Application Section
main-es5.js:1 Error: Cannot enable prod mode after platform setup. at e.enableProdMode (scripts.js:1) at Module.zUnb (main-es5.js:1)
Read more >
enableProdMode - Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found