New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng build environment option not working since upgrade to 1.2.3 #7118

Closed
Bidthedog opened this Issue Jul 24, 2017 · 15 comments

Comments

Projects
None yet
10 participants
@Bidthedog

Bidthedog commented Jul 24, 2017

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

@sh33dafi

This comment has been minimized.

Show comment
Hide comment
@sh33dafi

sh33dafi Jul 24, 2017

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 commented Jul 24, 2017

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

@Bidthedog

This comment has been minimized.

Show comment
Hide comment
@Bidthedog

Bidthedog Jul 24, 2017

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 commented Jul 24, 2017

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.

@dprandzioch

This comment has been minimized.

Show comment
Hide comment
@dprandzioch

dprandzioch Jul 24, 2017

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

dprandzioch commented Jul 24, 2017

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

@bmcswee

This comment has been minimized.

Show comment
Hide comment
@bmcswee

bmcswee Jul 24, 2017

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 commented Jul 24, 2017

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

@sh33dafi

This comment has been minimized.

Show comment
Hide comment
@sh33dafi

sh33dafi Jul 24, 2017

@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 commented Jul 24, 2017

@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

@Bidthedog

This comment has been minimized.

Show comment
Hide comment
@Bidthedog

Bidthedog Jul 24, 2017

For now I've downgraded to 1.1.1 again

Bidthedog commented Jul 24, 2017

For now I've downgraded to 1.1.1 again

@bmcswee

This comment has been minimized.

Show comment
Hide comment
@bmcswee

bmcswee Jul 24, 2017

@sh33dafi it does look like you are right.

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

Not good!

bmcswee commented Jul 24, 2017

@sh33dafi it does look like you are right.

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

Not good!

@bmcswee

This comment has been minimized.

Show comment
Hide comment
@bmcswee

bmcswee Jul 24, 2017

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

It must be something upstream

bmcswee commented Jul 24, 2017

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

It must be something upstream

@bmcswee

This comment has been minimized.

Show comment
Hide comment
@bmcswee

bmcswee Jul 24, 2017

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

bmcswee commented Jul 24, 2017

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

@rokerkony

This comment has been minimized.

Show comment
Hide comment
@rokerkony

rokerkony Jul 24, 2017

enhanced-resolve@3.3.0 helped me as well... thx @bmcswee!

my case was failing already on ng test

rokerkony commented Jul 24, 2017

enhanced-resolve@3.3.0 helped me as well... thx @bmcswee!

my case was failing already on ng test

@filipesilva

This comment has been minimized.

Show comment
Hide comment
@filipesilva

filipesilva Jul 24, 2017

Member

Closing in favor #7113, it seems to be the same issue and it's easier to communicate there. Apologies for the inconvenience.

Member

filipesilva commented Jul 24, 2017

Closing in favor #7113, it seems to be the same issue and it's easier to communicate there. Apologies for the inconvenience.

@muchrm

This comment has been minimized.

Show comment
Hide comment
@muchrm

muchrm Aug 3, 2017

enhanced-resolve@3.3.0 it's work for me!
thx @bmcswee

muchrm commented Aug 3, 2017

enhanced-resolve@3.3.0 it's work for me!
thx @bmcswee

@nicholasserra

This comment has been minimized.

Show comment
Hide comment
@nicholasserra

nicholasserra Dec 14, 2017

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 commented Dec 14, 2017

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!

@gauravsaluja2006

This comment has been minimized.

Show comment
Hide comment
@gauravsaluja2006

gauravsaluja2006 Dec 21, 2017

@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 commented Dec 21, 2017

@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

@abdus1975

This comment has been minimized.

Show comment
Hide comment
@abdus1975

abdus1975 Jan 30, 2018

enhanced-resolve@3.3.0 it's work for me!
thanks to @bmcswee

abdus1975 commented Jan 30, 2018

enhanced-resolve@3.3.0 it's work for me!
thanks to @bmcswee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment