Schaki
Schaki

Reputation: 1791

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?

Upvotes: 5

Views: 5244

Answers (2)

EACUAMBA
EACUAMBA

Reputation: 641

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

Upvotes: 9

Rafael Zasas
Rafael Zasas

Reputation: 993

The build command flag --configuration=production is fairly new. If you are still using an older version of the Angular CLI (different from framework) you need to run ng build --prod

Upvotes: 0

Related Questions