Skip to content

isDevMode not working in library: "cannot enable prod mode after platform setup" #36190

@hiepxanh

Description

@hiepxanh

🚀 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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: coreIssues related to the framework runtimecore: bootstrap

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions