angulartypescriptangular-cliangular12

Production environment variable doesn't seem to be set


EDIT: I've now upgraded the project to ng13 and the problem persists.

I'm building an Angular 12 13 app (originally generated in maybe version 8 or 9). My build command is ng build --configuration=production --output-hashing=all

and I'm expecting to see MYAPP written in the browser console on app start, but doesn't appear. (In reality I want to do other things but console.log illustrates my problem)

Snippet below from main.ts

if (environment.production) {
  enableProdMode();
  console.log("MYAPP");
}

Any ideas?


Solution

  • You need to tell angular how to change the environment

    Add something like this in your angular .json in configurations production

    "fileReplacements": [
                                {
                                    "replace": "src/environments/environment.ts",
                                    "with": "src/environments/environment.prod.ts"
                                }
                            ],
    

    enter image description here