Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

environment.production variable always true inside app.module.ts

I am trying to set a config setting in my app.module file so that it's different depending on if I'm in production or not.

My environment.ts file has

export const environment = {
  production: false
};

My environment.prod.ts file has

export const environment = {
  production: true
};

In my app.module.ts file I am attempting something like this

imports: [
    BrowserModule,
    AppRoutingModule,
    LoggerModule.forRoot({
      level: (environment.production ? NgxLoggerLevel.OFF : NgxLoggerLevel.DEBUG)
    }),
...

When I do console.log(environment.production) anywhere it tells me this value is false as it should be while I am in the development environment.

My problem is that it seems to be acting as true in my app.module file. I'm trying to set my log statements to be disabled on the production environment in this case, but they are also getting disabled in development and production. (If I flip my conditional statement then they get enabled in both dev and production). So it's as if it's reading environment.production to be true when it shouldn't be.

Can the environment.production variable not be used like this in app.module or am I missing something else here?

like image 962
abney317 Avatar asked Jun 15 '26 17:06

abney317


1 Answers

I was directly importing the production version directly at the top of app.module.ts

import { environment } from 'src/environments/environment.prod';

instead of

import { environment } from 'src/environments/environment';
like image 74
abney317 Avatar answered Jun 17 '26 12:06

abney317



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!