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

ng build environment option not working since upgrade to 1.2.3

Open Bidthedog opened this issue 9 years ago • 16 comments

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

Bidthedog avatar Jul 24 '17 11:07 Bidthedog

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

sh33dafi avatar Jul 24 '17 11:07 sh33dafi

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 avatar Jul 24 '17 11:07 Bidthedog

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

dstapp avatar Jul 24 '17 11:07 dstapp

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 avatar Jul 24 '17 12:07 bmcswee

@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

sh33dafi avatar Jul 24 '17 12:07 sh33dafi

For now I've downgraded to 1.1.1 again

Bidthedog avatar Jul 24 '17 12:07 Bidthedog

@sh33dafi it does look like you are right.

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

Not good!

bmcswee avatar Jul 24 '17 12:07 bmcswee

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

It must be something upstream

bmcswee avatar Jul 24 '17 12:07 bmcswee

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

bmcswee avatar Jul 24 '17 12:07 bmcswee

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

my case was failing already on ng test

rokerkony avatar Jul 24 '17 12:07 rokerkony

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.

filipesilva avatar Jul 24 '17 16:07 filipesilva

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

muchrm avatar Aug 03 '17 09:08 muchrm

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 avatar Dec 14 '17 21:12 nicholasserra

@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

gauravsaluja2006 avatar Dec 21 '17 09:12 gauravsaluja2006

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

abdus1975 avatar Jan 30 '18 02:01 abdus1975

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.