Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app that uses isDevMode() api, cuases an error when built or served in prod mode #3495

Closed
forforeach opened this issue Dec 9, 2016 · 6 comments

Comments

@forforeach
Copy link

OS?

Windows 10

Versions.

angular-cli: 1.0.0-beta.22-1
node: 6.5.0
os: win32 x64

Repro steps.

  1. Create an app using CLI
  2. Add reference to isDevMode
  3. Use isDevMode()
  4. Serve or build an app with --prod flag
if (isDevMode()) {
  console.log('devmode');
}
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

The log given by the failure.

Uncaught Error: Cannot enable prod mode after platform setup.
@ application_ref.js:43367
@ main.ts:9r
@ bootstrap 521fad9…:52690
@ main.cd1f6e0….bundle.js:222r
@ bootstrap 521fad9…:52window.webpackJsonp
@ bootstrap 521fad9…:23(anonymous function)
@ main.cd1f6e0….bundle.js:1


@nweldev
Copy link
Contributor

nweldev commented Dec 9, 2016

I didn't investigated that enough for now, but I could reproduce it, and it seems to be an angular/angular issues. I'll search any existing issue about that and investigate more as soon as I could.

@nweldev
Copy link
Contributor

nweldev commented Dec 9, 2016

Found it : angular/angular#10643
It's still in progress, so we could remove the enableProdMode in environment.prod.ts by default in the meantime ... Anyone have an idea about that ?

Edit : from angular/angular#12200 : "the setting has to agree what was used in the compiler setting, otherwise Angular does not work." - maybe there is something to investigate in that field ...

@nweldev nweldev mentioned this issue Dec 9, 2016
@clydin
Copy link
Member

clydin commented Dec 9, 2016

This is expected behavior. You can't use isDevMode before enableProdMode.

@martinmcwhorter
Copy link

Shouldn't you check the environment provider rather than call isDevMode()?

@filipesilva
Copy link
Contributor

As @clydin said, you can't use isDevMove before enableProdMode. It might seem that it isn't happening in that order, but remember that you're calling the AppModule import before the code in main.ts runs.

There might be something to angular/angular#12200, but this will probably be an API change that we'll implement when available.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants