Uncaught Error: Cannot enable prod mode after platform setup-Angular 11

Viewed 121

After upgrading my project to Angular 11 I've started seeing this error when running the project locally with enableProdMode();

When I comment out enableProdMode() the project runs as expected and prior to the upgrade I never encounter this issue.

Is there something that needs to be changed with the upgrade?

zone-evergreen.js:659 Unhandled Promise rejection: Cannot enable prod mode after platform setup. ; Zone: <root> ; Task: Promise.then ; Value: Error: Cannot enable prod mode after platform setup.
    at enableProdMode (core.js:28904)
    at main.ts:14
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Zone.run (zone-evergreen.js:123)
    at zone-evergreen.js:857
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Zone.runTask (zone-evergreen.js:167)
    at drainMicroTaskQueue (zone-evergreen.js:569) Error: Cannot enable prod mode after platform setup.
    at enableProdMode (http://localhost:4200/vendor.js:85403:15)
    at http://localhost:4200/main.c94e9e776e3b8ac4ba8b.hot-update.js:31:77
    at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:9506:30)
    at Zone.run (http://localhost:4200/polyfills.js:9265:47)
    at http://localhost:4200/polyfills.js:9999:40
    at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:9541:35)
    at Zone.runTask (http://localhost:4200/polyfills.js:9309:51)
    at drainMicroTaskQueue (http://localhost:4200/polyfills.js:9711:39)
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from '@app/app.module';
import { ClientConfig } from '@app/core/models/api/client-config.model';
import { hmrBootstrap } from './hmr';

fetch('assets/client-config.json')
  .then((response) => response.json())
  .then((configJson) => {
    const config = configJson as ClientConfig;
    if (config.production) {
      enableProdMode();
    }

    const bootstrap = () => platformBrowserDynamic([{ provide: ClientConfig, useValue: config }]).bootstrapModule(AppModule);

    if (config.hmr) {
      hmrBootstrap(module, bootstrap);
    } else {
      bootstrap().catch((err) => console.error(err));
    }
  });
0 Answers
Related