Build -prod don't use environment.prod.ts parameters
Please provide us with the following information:
OS?
Windows 10 (32bits)
Versions.
@angular/cli: 1.0.0-beta.31 node: 7.5.0 os: win32 ia32 @angular/common: 2.4.7 @angular/compiler: 2.4.7 @angular/core: 2.4.7 @angular/forms: 2.4.7 @angular/http: 2.4.7 @angular/platform-browser: 2.4.7 @angular/platform-browser-dynamic: 2.4.7 @angular/router: 3.4.7 @angular/cli: 1.0.0-beta.31 @angular/compiler-cli: 2.4.7
Repro steps.
When building with -prod param, the environment.prod.ts in src/environments folder is not use !
The log given by the failure.
Mention any other details that might be useful.
It was ok with the angular-cli 1.0.0-beta.26.
Thanks! We'll be in touch soon.
All others params (target, env..) fail the same way.
#4710
can you share the code where you are using the environment file? May I assume you are "providing" the environment file?
It's not being used anywhere... we just use the same build command across different projects for consistency. Only 1 of 5 projects uses it and this isn't one of them.
Can you post an example on how you are loading the environments file?
Please be sure to import from environments/environment and not environments/environment.prod
The note at the top of environment file explains this:
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `angular-cli.json`.
Try with a brand new project (made with ng init).
Always en dev mode with ng serve --env=prod !
@bvaissade I did the following on app.component.ts:
import {environment} from './../environments/environment'
...
ngOnInit(){
console.log('ENV IS ', environment)
}
My environment.prod.ts looks like:
export const environment = {
production: true,
test: 'hi'
};

Once I ran the applications I get those parameters.
I have try your code. Same bug ! Here my environment.prod.ts
export const environment = {
production: true
};
Here my app.component.ts :
import { Component } from '@angular/core';
import {environment} from './../environments/environment'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
ngOnInit(){
console.log('ENV IS ', environment)
}
}
Here my console log after ng serve --env=prod :
Mode DEV...
app.component.ts: ENV IS Object production: false
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
I have the same problem after upgrading from [email protected] to @angular/[email protected].
@angular/cli: 1.0.0-beta.30
node: 6.9.0
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.30
@angular/compiler-cli: 2.4.7
When I create a new project it works though. I'm struggling to find the difference …
@bvaissade I now understand that --target=production sets the build target. The alias is -prod. But to set your environment you need to explicitly set --environment=prod as well.
This used to work in v1.0.0-beta.24, but fails in v1.0.0-beta.30:
ng serve --prod
This works as an alternative for me:
ng serve --target=production --environment=prod
Ok I have try with @ukaaa command
ng serve --target=production --environment=prod
but allway en DEV mode :-(
@bvaissade I don't see that with the latest version (beta.32-3):

Can't test it ! Lot of errors in my .angular.cli.json.
Like :
"$schema":"./node_modules/@angular/cli/lib/config/schema.json",``
And ng new don't works.
@bvaissade I'm sorry, I could have sworn it works but today I try again and it doesn't. This is very frustrating.
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.
If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.