Angular: Weird if statement behaviour in app.module.ts

we recently experienced weird behaviour in our app.module.ts. We were using environment.ts and file to include/exclude specific library in imports array of the module(library should be excluded for production build). It looked something like this:

import { environment } from '../environments/environment'
  imports: [
    environment.production ? [] : libraryXXX,

we found out after days of barren investigation that libraryXXX is included in build every time, even with –prod flag. We tested what’s the problem – the value from environment.ts/prod.ts file was read correctly, but for whatever reason comparision always returned false. What I mean by always: replacing above fragment with:

environment.production == true ? [] : libraryXXX


environment.production == false ? [] : libraryXXX

did not change a thing – library WAS ALWAYS included. Like the if statement was broken(?). Extracting it to variable didn’t change a thing. We ended up doing semi-hacky solution like:


import { libraryXXX } from 'whatever'

export const environment = {
  production: false,
  libraryXXX: libraryXXX

export const environment = {
  production: true,
  libraryXXX: []

and simply referening to environment.libraryXXX in app.module.ts. But out of the curiosity – can anyone explain to me why simple if statement failed? Since it was app.module.ts I could not debug it, or even see console output, to know what’s going on. Anyone has an idea?

Source: New feed
Source Url Angular: Weird if statement behaviour in app.module.ts