Cannot enable prod mode after setting up the platform. Angular 5 Production Assembly

Error:

Uncaught Error: Cannot enable prod mode after platform setup. at main.bundle.js:1 

Happening:

An error occurred while starting the application after creating the assembly using . However, development assemblies compiled using or work fine. ng build --prod ng serve ng build

What I tried:

-Upgrading global and local @angular/clito the latest version ie 1.6.0, following these answers.

package.json:

{
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "auth0-js": "^8.11.3",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "jquery": "^3.2.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.16",
    "@types/node": "~6.0.60",
    "@types/rx": "^4.1.1",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "^2.6.2"
  }
}

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';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule).catch(err => console.log(err));

Minimum code to reproduce the error:

git / cli-reproapp

+4
source share
1 answer

In the sample application that you specified in git / cli-reproapp , the error occurs because of this line: -

export const isInDevMode = isDevMode();

cli-reproapp/src/app/app.constants.ts. isInDevMode, . isDevMode() ( enableProdMode()), .

export function isInDevMode():boolean {
    return isDevMode();
}

, , isInDevMode isInDevMode(). app.component.ts

this.title = isInDevMode ? 'App in dev mode works.' : 'App is prod mode works.'

: -

this.title = isInDevMode() ? 'App in dev mode works.' : 'App is prod mode works.'

git/cli-reproapp (working).

+1

Source: https://habr.com/ru/post/1690434/


All Articles