angular: `isDevMode` not working in library: "cannot enable prod mode after platform setup"

🚀 feature request

Relevant Package

This feature request is for @angular/core

Description

A clear and concise description of the problem or missing capability...

Yeah, here is the problem. I have multi project: image And then instead of having 2 * 4 = 8 enviroment file duplicate for firebase information: image I really want to create only one module like this to easy import firebase module once (instead of 4 times): image but since isDevMode is calling in my firebase module, and it is call before enableProdMode() calling out. so I got this error image and even more, we can do tree sakeable module:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    isProdMode() ? [] : DevModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Describe the solution you’d like

If you have a solution in mind, please describe it.

somekindof isProdMode() which is can read enviroment file quickly. Doesn’t have to wait main.ts That can be useful for reading prod mode from library. Or multi project workspace.

Describe alternatives you’ve considered

Have you considered any alternative solutions or workarounds?
solution video: https://youtu.be/UsBDLaCnALU

// environment.prod.ts 
(global as any).prod = true;
// firebase.module.ts
console.log('isProd??', (global as any).prod);

The idea behind is simple.

  • some magic behind (check env file or anything that know that it’s production mode) that show it’s production in varible
  • allow me call isProdMode() before call main.ts file instead of giving me cannot enable prod mode after platform setup like I’m calling isDevMode()

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

Just place your configuration to environments for each type of environment, then import it in your code

import { anythingExportedFromThisFile } from 'path/to/src/environments/environment';

And when you run the build/serve step with provided env, Angular CLI will replace the environment.ts to your destination env for you.