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

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 10
  • Comments: 16 (1 by maintainers)

Most upvoted comments

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

Broken upstream package is enhanced-resolve@3.4.0

npm i enhanced-resolve@3.3.0 seems to have fixed the issue for me

@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?

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!

@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

@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