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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tiepptcommented, Mar 23, 2020

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.

0reactions
angular-automatic-lock-bot[bot]commented, Nov 26, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Error: Cannot enable prod mode after platform setup.
I have not use isDevMode()。 The log given by the failure. open the page in the chrome,console print error:. vendor.9844cf9b240425f86ca5.
Read more >
Cannot enable prod mode after platform setup. Angular 5 ...
In the sample app you provided at git/cli-reproapp the error is occurring because of this line :- export const isInDevMode = isDevMode();.
Read more >
isDevMode - Angular
By default, this is true, unless enableProdMode is invoked prior to calling this method or the application is built using the Angular CLI...
Read more >
@angular/core@15.0.4 - jsDocs.io
isDevMode : () => boolean;. Returns whether Angular is in development mode. By default, this is true, unless enableProdMode is invoked prior ...
Read more >
Writing Your Own Extension - Quarkus
Extensions should see the configuration holistically as a Quarkus application instead of focusing on the library experience.
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