Angular-cli: ng build environment option not working since upgrade to 1.2.3

Created on 24 Jul 2017  Â·  16Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

MINGW64 /f/code_temp/testing (master)
$ ng -v
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ â–³ \ | '_ \ / _| | | | |/ _ | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ __| |_|__, |__,_|_|__,_|_| ____|_____|___|
|___/
@angular/cli: 1.2.3
node: 6.9.4
os: win32 x64
@angular/animations: 4.3.1
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.3
@angular/compiler-cli: 4.3.1
@angular/language-service: 4.3.1

Repro steps.

  • Download this zip - https://www.dropbox.com/s/zb7f2pjx5lenbsx/testing.zip?dl=0
  • Zip has been generated today with @angular/cli 1.2.3. The only modifications I've made are to add two new environments (LIVE and TEST), remove the "prod" environment from .angular-cli.json, and add the two new environment files in /environments
  • run npm install
  • run any variation of the ng build command, with an environment parameter, e.g:

ng build -e TEST
ng build -env:TEST
ng build --environment TEST
ng build --environment "TEST"

etc...

  • After each run, check if the dist/main.bundle.js file contains the transformed properties. The "dev" settings are used regardless of the environment I specify.

The log given by the failure.


N/A

Desired functionality.


The relevant environment file should be used to perform transformations on the final environment settings. I believe I have tried all variations and read all the documentation.

Because we have to perform the transformation at build time, these environment names are shared with our back-end build. Case is important, and "prod" is not required due to the naming of our environments.

Mention any other details that might be useful.


This was working in 1.1.1 on our build server. I used "ng build -e TEST" or "ng build -e LIVE" previously.

This happens locally (Win 8.1) and on our build server (Current VSO Hosted Agent - cli version confirmed).

Most helpful comment

The thread for #7113 has found the issue and solution.

Broken upstream package is [email protected]

npm i [email protected] seems to have fixed the issue for me

All 16 comments

Having the same issue on OS X (10.12) Using cli v 1.2.3
in my case ng build --environment prod etc is always falling back to dev environment settings

Just found some new docs here: https://github.com/angular/angular-cli/wiki/build

Not 100% sure what the difference between a target and an environment is?

However, I've just tried the new docs and I'm still getting the same behavior:

ng build --target=development --environment=TEST
ng build --target=development --environment=LIVE

All still use the DEV settings

ng build --target=production --environment=TEST

Throws the following error:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'F:\code_temp\testing\src'
@ ./src/main.ts 3:0-74
@ multi ./src/main.ts

This seems to be caused by the --target=production flag

ng build --ENV:TEST

Shows a warning:

$ ng build --env:TEST
The option '--env:TEST' is not registered with the build command. Run ng build --help for a list of supported options.

@Bidthedog We have the same problem (although I'm not sure if this is related to the original problem?):

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in [...]

It seems not to be about the environment itself but rather about --aot, which is automatically enabled when --environment=production is set. I was able to build the project using ng build [...] --environment=production --aot=false. Can someone try and verify if this "solves" the problem? Interestingly starting this morning all our builds fail on CI because of this errors, although no new @ng/cli version was released. Maybe a dependency of angular-cli updated?

Big +1 to @dprandzioch. It does seem that aot is the issue. I was able to build using
ng build --environment=prod --aot=false

I also think he is right about a dependency updating. This exact version of my code was building Friday afternoon, but this morning it is not. One more argument for using npm-shrinkwrap I suppose

Hopefully this gets some dev attention ASAP

@bmcswee & @dprandzioch is the resulting build from ng build --environment=prod --aot=false using the properties from environment.prod.ts?
Here everything builds but it always using the properties from environment.ts

For now I've downgraded to 1.1.1 again

@sh33dafi it does look like you are right.

"isDevMode()" is returning true when built with "ng build --environment=prod --aot=false"

Not good!

@Bidthedog I have downgraded to 1.1.1 and am still having the same build error.

It must be something upstream

The thread for #7113 has found the issue and solution.

Broken upstream package is [email protected]

npm i [email protected] seems to have fixed the issue for me

[email protected] helped me as well... thx @bmcswee!

my case was failing already on ng test

Closing in favor https://github.com/angular/angular-cli/issues/7113, it seems to be the same issue and it's easier to communicate there. Apologies for the inconvenience.

[email protected] it's work for me!
thx @bmcswee

I seem to still be having this issue. Angular-cli 1.6.1, angular-core 4.4.6.

trying:
ng build --environment=staging --target=production

.angular-cli.json env settings:

  "environmentSource": "environments/environment.ts",
  "environments": {
      "dev": "environments/environment.ts",
      "staging": "environments/environment.staging.ts"
  },

But the staging variables are not being respected, it falls back to the dev settings.

I'm also finding it troublesome that I can pass any random environment name to the build command and it will _not_ raise an error. Making it very hard to debug configuration at this point.

Any help appreciated, thanks!

@nicholasserra I had the same issue. So, after trying everything i could, what did the trick was:

rm -r node_modules
npm install

see if that helps you

[email protected] it's work for me!
thanks to @bmcswee

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IngvarKofoed picture IngvarKofoed  Â·  3Comments

jbeckton picture jbeckton  Â·  3Comments

JanStureNielsen picture JanStureNielsen  Â·  3Comments

NCC1701M picture NCC1701M  Â·  3Comments

MateenKadwaikar picture MateenKadwaikar  Â·  3Comments