If you want to know the mode of Angular, as @yurzui said, you need to call { isDevMode } from @angular/core but it can return false only if you call enableProdMode before it.
If you want to know the build environment, in other words, if your app is running minified or not, you need to set a build variable in your build system... Using Webpack, for example, you should have a look at definePlugin.
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module'
platformBrowserDynamic().bootstrapModule(AppModule);
enableProdMode();
This was my code, so I got the same error. I just interchanged line 3 and 4. Then the issue is fixed. So before bootstrapping module we should enable --prod mode.
After called once, the value is locked and won't change any more...
By default, this is true, unless a user calls enableProdMode before calling this.
I've found that calling isDevMode() from an ng build --prod build always returns true and always locks you into running in dev mode. Instead, check environment.production to see if you are in production. Then you will stay in production mode.
You should be careful that you check the return value of the isDevMode() function.
My setup was failing because i was checking for existence: if (isDevMode) was always true, even in production because i declared it with import { isDevMode } from '@angular/core';.