angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.73k stars 11.98k forks source link

AOT build fails #7113

Closed adwd closed 7 years ago

adwd commented 7 years ago

Bug Report or Feature Request (mark with an x)

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

Versions.

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.2.3
node: 6.11.1
os: darwin 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.

$ ng new hello
$ cd hello
$ ng build --prod

The log given by the failure.

$ ng build --prod
Hash: edf6fb3ccb1b82fa940c
Time: 10775ms
chunk    {0} polyfills.71b130084c52939ca448.bundle.js (polyfills) 177 kB {4} [initial] [rendered]
chunk    {1} main.e81f19d3f6b27a436c79.bundle.js (main) 1.09 kB {3} [initial] [rendered]
chunk    {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk    {3} vendor.f7457d5ac1e9743fd76f.bundle.js (vendor) 849 kB [initial] [rendered]
chunk    {4} inline.18e445e37a0efd4dcfa2.bundle.js (inline) 0 bytes [entry] [rendered]

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

Desired functionality.

aot build runs

Mention any other details that might be useful.

Maybe, enhanced-resolve 3.4.0 is cause. https://github.com/webpack/enhanced-resolve/issues/98

ng build --prod runs successfully after npm i enhanced-resolve@3.3.0 .

mchmielarski commented 7 years ago

I noticed same problem and after npm i enhanced-resolve@3.3.0 I can build with AOT

MasDevProject commented 7 years ago

Same problem here

serhiisol commented 7 years ago

@mchmielarski That's a very nice guess 👍

zucker-rdrg commented 7 years ago

Same here. workaround: npm install enhanced-resolve@3.3.0

jahller commented 7 years ago

thanks for the solution guys, this problem just cost us the whole morning. adding enhanced-resolve@3.3.0 solved it.

ChrisCherryfarmer commented 7 years ago

Thx, same here. enhanced-resolve@3.3.0 solved the issue.

kondi0 commented 7 years ago

The same here!

enhanced-resolve@3.3.0 solved it!

hpyou commented 7 years ago

thanks god for this issue, i fixed this problem the whole day

thegitty commented 7 years ago

Workaround with "enhanced-resolve@3.3.0" seems to work on Mac OS but not on Linux!? Can anyone confirm this behavior?

sculeb commented 7 years ago

works on linux ubuntu 16.04 for me

TautvydasDerzinskas commented 7 years ago

Same issue.

TautvydasDerzinskas commented 7 years ago

Guys, you should really use fixed dependency versions for Angular-Cli. It's been a millionth time when everything breaks because in new versions of sub dependencies there is something unexpected...

cankayacan commented 7 years ago

The angular-cli version is already fixed for us which is 1.3.1 but still we have this error.

bmcswee commented 7 years ago

Same issue for me. Resolved with enhanced-resolve@3.3.0 on Ubuntu Server.

RIP the first 2 hours of my morning.

erashu212 commented 7 years ago

It worked for me too with 3.3.0.

amiram commented 7 years ago

Still we have error in AOT even with 3.4.1. Also in development the environment.ts is not overwritten with the appropriate environment file

webmutation commented 7 years ago

This breaks all builds, amazing fun was had today! PLZ PLZ PLZ move to fixed dependency.

tkoenig89 commented 7 years ago

Issue still exists withenhanced-resolve@3.4.1 here. Same issue showing up. Staying at 3.3.0 for now.

Pittan commented 7 years ago

When creating new project with fresh installed angular/cli 1.2.0 fails, too :( I used yarn for package management.

pvanhemmen commented 7 years ago

Same problem here. npm install enhanced-resolve@3.3.0 resolved the issue for me temporarily, but only when it's installed as an addition into an already up and running project. Deployment through a fresh install with npm install with this dependency set in package.json does not work.

This is a major bug, because it breaks a running deployment pipeline and with it the whole production setup.

mscherer82 commented 7 years ago

I'm on windows and adding enhanced-resolve@3.3.0 doesn't work for me.

angelnikolov commented 7 years ago

@mscherer82 Did you run npm install? If you did, you can try deleting node_modules and re-running it. It worked for me.

mscherer82 commented 7 years ago

@angelnikolov yes, I deleted node_modules and reinstalled all packages.

angelnikolov commented 7 years ago

Hm, can you try running npm ls and see if this is your enhanced-resolve version +-- enhanced-resolve@3.3.0

eelokets commented 7 years ago

@pvanhemmen You should install enhanced-resolve after npm install. As temporary resolve it's ok. image

pvanhemmen commented 7 years ago

@vicetjs That's what I did and the only way it works for me, too. Thanx for your help!

benelliott commented 7 years ago

In order to make my build server happy I forked angular/ngtools-webpack-builds and pinned enhanced-resolve at 3.3.0, then forked angular/cli-builds to point it at my ngtools fork. If anyone is interested they can try it out by changing their package.json to "@angular/cli": "github:benelliott/cli-builds#24a8837" (note however that both libraries will be at master, not a specific version).

bmcswee commented 7 years ago

@pvanhemmen I was able to get deployment via fresh install working again by using npm shrinkwrap after installing enhanced-resolve@3.3.0. This got my Jenkins build pipeline working fine again

This should also prevent upstream dependency breakage from harming my project in the future :)

pvanhemmen commented 7 years ago

@bmcswee Awesome, thanx for the tip!

mscherer82 commented 7 years ago

npm listgave me:


+-- @angular/cli@1.2.3
| +-- @ngtools/json-schema@1.1.0
| +-- @ngtools/webpack@1.5.2
| | +-- enhanced-resolve@3.4.1
...
| +-- webpack@2.4.1
...
| | +-- enhanced-resolve@3.4.1 deduped
...
+-- enhanced-resolve@3.3.0
dgetts192 commented 7 years ago

Installing enhanced-resolve 3.3.0 did the trick thank you!

kasperfp commented 7 years ago

Enhanced-resolve@3.3.0 did the trick for my project. Can somebody please explain me what this package does?

jakeNiemiec commented 7 years ago

https://github.com/angular/angular-cli/issues/4551 regression from months ago.

kasperfp commented 7 years ago

@jakeNiemiec This means I should uninstall the package at a later point in time, when the Angular team fixes the bug, right?

Cheers!

andreasonny83 commented 7 years ago

Guys, the enhanced-resolve@3.3.0 way-around doesn't work on my project. I still have the same error. Is there any update on this issue?

kasperfp commented 7 years ago

@andreasonny83 did you run exactly this command:

npm i enhanced-resolve@3.3.0

Make sure to update Angular CLI and Node as well.

jakeNiemiec commented 7 years ago

Just to be clear (@kasperfp, @andreasonny83): ❌ Won't work (this is what npm@^5 put in my package.json when I ran npm i enhanced-resolve@3.3.0): "enhanced-resolve": "^3.3.0", ✅ Will Work: "enhanced-resolve": "3.3.0",

See more complete comment by @Gustorn below: https://github.com/angular/angular-cli/issues/7113#issuecomment-317483817

mydata commented 7 years ago

jakeNiemiec comment worked for me too. Is there any fix planned for this breaking change?

filipesilva commented 7 years ago

Hi all,

This seems to be a bug/breaking change in enhanced-resolve, a dependency of webpack. Will try to talk to the Webpack maintainers about this.

Meanwhile pin it to "enhance-resolve": "3.3.0" in your package.json.

Edit: issue on enhanced-resolve is https://github.com/webpack/enhanced-resolve/issues/98.

benelliott commented 7 years ago

@filipesilva Worth noting that it is also a direct dependency of @ngtools/webpack.

filipesilva commented 7 years ago

@benelliott good point.

warmans commented 7 years ago

@lsunkara AFAIK that will result in a non-aot build which might not be desirable for everyone.

filipesilva commented 7 years ago

@warmans is correct. Please see https://github.com/angular/angular-cli/wiki/build#--dev-vs---prod-builds for effect of the --prod flag.

webmutation commented 7 years ago

@bmcswee :+1: I am adding shrinkwrap --dev to all things now. Just takes a bit more discipline, tired of all these breaking changes on npm packages. So that is a great tip to all.

lsunkara commented 7 years ago

@warmans, I agree, ng build --env=prod is not desirable. Pinning to enhanced-resolve to 3.3.0 only works. Thanks.

jakeNiemiec commented 7 years ago

Relevant issues in the enhance-resolve repo:

Changes since 3.3.0.

renatop7 commented 7 years ago

Nothing fixes this error for me. Already tried everything writen in this thread.

If anybody did something different please let me know!

zsparal commented 7 years ago

@renatop7 I think some of the workaround suggestions here won't actually save the proper version in your package.json. Here's how I fixed it:

  1. Remove every reference to enhanced-resolve from your package.json (if you already have some from other workarounds)
  2. Run the command: npm i -DE enhanced-resolve@3.3.0 (-DE should work consistently between npm4 and npm5)
  3. (Optional) Delete your node_modules folder to verify that it works with a clean install
  4. npm install, then run the production build

Edit: Also if you're using npm5 I'd try regenerating package-lock.json (just delete it before step 4). I don't think this applies to too many people, the build shouldn't have even broken if you have a lockfile.

filipesilva commented 7 years ago

@Gustorn's that's a very good step by step guide, thanks!

warmans commented 7 years ago

@gustorn I also had to clear my npm cache to get the right version.