angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Build -prod don't use environment.prod.ts parameters

Open bvaissade opened this issue 9 years ago • 16 comments

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.

bvaissade avatar Feb 15 '17 10:02 bvaissade

All others params (target, env..) fail the same way.

bvaissade avatar Feb 15 '17 10:02 bvaissade

#4710

phillip-haydon avatar Feb 15 '17 10:02 phillip-haydon

can you share the code where you are using the environment file? May I assume you are "providing" the environment file?

deebloo avatar Feb 15 '17 13:02 deebloo

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.

phillip-haydon avatar Feb 15 '17 13:02 phillip-haydon

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`.

RicardoVaranda avatar Feb 15 '17 13:02 RicardoVaranda

Try with a brand new project (made with ng init). Always en dev mode with ng serve --env=prod !

bvaissade avatar Feb 15 '17 14:02 bvaissade

@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'
};

image

Once I ran the applications I get those parameters.

RicardoVaranda avatar Feb 15 '17 14:02 RicardoVaranda

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.

bvaissade avatar Feb 15 '17 16:02 bvaissade

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 …

ukaaa avatar Feb 16 '17 11:02 ukaaa

@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

ukaaa avatar Feb 16 '17 13:02 ukaaa

Ok I have try with @ukaaa command

ng serve --target=production --environment=prod

but allway en DEV mode :-(

bvaissade avatar Feb 16 '17 16:02 bvaissade

@bvaissade I don't see that with the latest version (beta.32-3):

image

filipesilva avatar Feb 17 '17 12:02 filipesilva

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 avatar Feb 17 '17 13:02 bvaissade

@bvaissade I'm sorry, I could have sworn it works but today I try again and it doesn't. This is very frustrating.

ukaaa avatar Feb 20 '17 10:02 ukaaa

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.

filipesilva avatar May 23 '17 11:05 filipesilva

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.