angular-cli: AOT build fails
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
.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 163
- Comments: 173 (31 by maintainers)
Links to this issue
Commits related to this issue
- fix(ui): fixdeps: https://github.com/angular/angular-cli/issues/7113 — committed to ovh/cds by sguiheux 7 years ago
- fix(@ngtools/webpack): pin enhanced-resolve See https://github.com/angular/angular-cli/issues/7113 and https://github.com/webpack/enhanced-resolve/issues/98 for context. This should be unpinned when... — committed to filipesilva/angular-cli by filipesilva 7 years ago
- fix(@ngtools/webpack): pin enhanced-resolve See https://github.com/angular/angular-cli/issues/7113 and https://github.com/webpack/enhanced-resolve/issues/98 for context. This should be unpinned when... — committed to angular/angular-cli by filipesilva 7 years ago
- fix(@ngtools/webpack): pin enhanced-resolve See https://github.com/angular/angular-cli/issues/7113 and https://github.com/webpack/enhanced-resolve/issues/98 for context. This should be unpinned when... — committed to angular/angular-cli by filipesilva 7 years ago
- fix(@ngtools/webpack): pin enhanced-resolve See https://github.com/angular/angular-cli/issues/7113 and https://github.com/webpack/enhanced-resolve/issues/98 for context. This should be unpinned when... — committed to angular/angular-cli by filipesilva 7 years ago
- Fix yarn version and address angular issue A new critical Angular issue was filed on 7/23/17 for angular-cli which breaks the production VIC UI plugin build. Production build uses Ahead-of-Time compi... — committed to jooskim/vic by jooskim 7 years ago
- Fix yarn version and address angular issue A new critical Angular issue was filed on 7/23/17 for angular-cli which breaks the production VIC UI plugin build. Production build uses Ahead-of-Time compi... — committed to jooskim/vic by jooskim 7 years ago
- chore(build): lock enhanced-resolve See https://github.com/angular/angular-cli/issues/7113 Closes #1700 — committed to ng-bootstrap/ng-bootstrap by pkozlowski-opensource 7 years ago
- fix(dependencies): upgrading node dependencies enhanced-resolve upgraded to v3.3.0 due to a compilation error with @angular/cli [#7113](https://github.com/angular/angular-cli/issues/7113) tsconfig.j... — committed to andreasonny83/awesome-typescript-loader by andreasonny83 7 years ago
- updated package.json for heroku issue (switched back to npm) (added enhance-resolve) based on https://github.com/angular/angular-cli/issues/7113#issuecomment-317723824 — committed to maschad/cloudCAST-Website by maschad 7 years ago
- fix(dependencies): upgrading node dependencies (#472) enhanced-resolve upgraded to v3.3.0 due to a compilation error with @angular/cli [#7113](https://github.com/angular/angular-cli/issues/7113) ... — committed to s-panferov/awesome-typescript-loader by andreasonny83 7 years ago
- fix(package.json): pin enhanced-resolve See [angular-cli#7113](https://github.com/angular/angular-cli/issues/7113) and [webpack/enhanced-resolve#98](https://github.com/webpack/enhanced-resolve/issues... — committed to andreasonny83/webpack by andreasonny83 7 years ago
- Trying fix https://github.com/angular/angular-cli/issues/7113 — committed to atereshkov/DiberWebClient by atereshkov 7 years ago
- Revert "Trying fix https://github.com/angular/angular-cli/issues/7113" This reverts commit 06cadb002ff8948a0b794651dc44a4851c2f732b. — committed to atereshkov/DiberWebClient by atereshkov 7 years ago
- Actualizar Angular CLI para evitar error ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' https://github.com/angular/angular-cli/issues/7125 https... — committed to webtrainingmx/angular-project-manager-avanzado by alex-arriaga 7 years ago
- Added enhanced-resolve to resolve build issues https://github.com/angular/angular-cli/issues/7113 — committed to Code-Mine-Development/CodeMine-Website-Web-Application by AdamiecRadek 7 years ago
- Added enhanced-resolve to resolve build issues https://github.com/angular/angular-cli/issues/7113 — committed to Code-Mine-Development/CodeMine-Website-Web-Application by AdamiecRadek 7 years ago
- Fix AOT build failure For more detail see https://github.com/angular/angular-cli/issues/7113 — committed to danielwiehl/edu-angular-change-detection by danielwiehl 7 years ago
- change build command and refactor scripts * Refactors npm scripts. * Changes build command to prods * Fixes production build * Upgrades angular-cli due to: https://github.com/angular/angular-cli/i... — committed to harunurhan/ng2-multi-record-editor by harunurhan 7 years ago
- fix(build): fix AOT issues when building for production See angular/angular-cli#7113. Additionally, remove no longer needed fix to yarn issue (yarnpkg/yarni#3485). — committed to adab1ts/veinapp by zuzust 6 years ago
I noticed same problem and after
npm i enhanced-resolve@3.3.0
I can build with AOTGuys, 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…
@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:enhanced-resolve
from yourpackage.json
(if you already have some from other workarounds)npm i -DE enhanced-resolve@3.3.0
(-DE
should work consistently between npm4 and npm5)node_modules
folder to verify that it works with a clean installnpm install
, then run the production buildEdit: Also if you’re using
npm5
I’d try regeneratingpackage-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.Hi all,
This seems to be a bug/breaking change in
enhanced-resolve
, a dependency ofwebpack
. Will try to talk to the Webpack maintainers about this.Meanwhile pin it to
"enhance-resolve": "3.3.0"
in yourpackage.json
.Edit: issue on
enhanced-resolve
is https://github.com/webpack/enhanced-resolve/issues/98.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 withnpm install
with this dependency set inpackage.json
does not work.This is a major bug, because it breaks a running deployment pipeline and with it the whole production setup.
We’ve released
1.2.4
/1.3.0-rc.1
to fix this issue. Updating should wholly prevent this issue without any other action needed.A huge thank you to @sokra for quick responses and zeroing into the issue.
Enhanced-resolve@3.3.0 did the trick for my project. Can somebody please explain me what this package does?
Same issue for me. Resolved with
enhanced-resolve@3.3.0
on Ubuntu Server.RIP the first 2 hours of my morning.
I’m on windows and adding
enhanced-resolve@3.3.0
doesn’t work for me.Issue still exists with
enhanced-resolve@3.4.1
here. Same issue showing up. Staying at 3.3.0 for now.This breaks all builds, amazing fun was had today! PLZ PLZ PLZ move to fixed dependency.
Workaround with “enhanced-resolve@3.3.0” seems to work on Mac OS but not on Linux!? Can anyone confirm this behavior?
@michaelsanford ah, I see now: the first error you get is actually causing the second:
Since that fails, AOT doesn’t compile anything really so you get the second error:
Which is true (but hard to interpret).
You have to fix the first error to get right of the second.
Just to be clear (@kasperfp, @andreasonny83):❌ Won’t work (this is whatnpm@^5
put in mypackage.json
when I rannpm 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
We got a new fix in yesterday (https://github.com/angular/angular-cli/pull/7169), under
1.2.6
/1.3.0-rc.3
. We hope that it will allowenhanced-resolve@3.4.1
and below to resolve correctly even under yarn.@russelltrafford it’s hard to say and depends on your package manager. If you’re on npm, that should be fine. To test, remove
package-lock.json
/yarn.lock
/node_modules
, updatepackage.json
withenhanced-resolve@3.3.0
,npm install
,ng build --aot
. If you get an error about$$gendir
, it doesn’t work. If you don’t, it’s working.@michaelsanford are you using npm or yarn? Can you provide me with your package.json? I can test it myself and see what’s happening.
@play2web doesn’t get resolved if you are using yarn…
@pvanhemmen I was able to get deployment via fresh install working again by using
npm shrinkwrap
after installingenhanced-resolve@3.3.0
. This got my Jenkins build pipeline working fine againThis should also prevent upstream dependency breakage from harming my project in the future 😃
@pvanhemmen You should install enhanced-resolve after npm install. As temporary resolve it’s ok.
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
Could somebody maybe re-open this ticket or should we create a new one specific for yarn?
and with version 1.3.0-rc.1 I see:
A “official” statement would be awesome if the issue detected by sokra (https://github.com/webpack/enhanced-resolve/issues/98#issuecomment-317516344) is on the roadmap for the next release. Or what is to do, to fix this?
Status quo:
@ngtools/webpack
is not usable as standalone with webpack >3.3.0
@angular/cli
is not usable with yarn >0.24.6
@lsunkara AFAIK that will result in a non-aot build which might not be desirable for everyone.
@mchmielarski That’s a very nice guess 👍
upgrading angular/cli to 1.2.4 resolve the problem for me .
this issue creeped up for me using ngtools/webpack for my angular build… not using angular-cli and I specifically used ngtools/webpack 1.5.3 and the issue resolved itself… with using that other plugin…
So for people using ngtools/webpack simply use at this time version 1.5.3… adding the other package won’t do anything no matter what version you use.
For cli projects
0.24.6
3.3.0
For non-cli projects using
@ngtools/webpack
0.24.6
3.3.0
3.3.0
Yarn users: there is a dedicated discussion topic in https://github.com/angular/angular-cli/issues/7136#issuecomment-318313404.
To all users: you should not have
webpack
in your package.json. Webpack does not work properly with multiple versions installed at the same time. See https://github.com/angular/angular-cli/issues/6417#issuecomment-315708400 for more information.We’ll be updating
@ngtools/webpack
(as per https://github.com/webpack/enhanced-resolve/issues/98#issuecomment-317518593) but this is not something that will happen on short term as it requires a fair bit of work.Meanwhile we’ve pinned
enhanced-resolve@3.3.0
(https://github.com/angular/angular-cli/pull/7123) andwebpack@3.3.0
(https://github.com/angular/angular-cli/pull/71300). These result in dependencies being properly resolved.@samridh90 no idea what’s happening in your https://github.com/angular/angular-cli/issues/7113#issuecomment-317599036 but seems unrelated. Can you open a new issue please?
As much as I hate this workaround, you can technically “fix” the
yarn.lock
file by hand if downgradingyarn
is not an option for you. After upgrading your Angular-related dependencies your lockfile should have something like this:Replace that with:
and you’ll be able to build with 0.27.5 again. Please note that as the file itself tells you, one shouldn’t edit the
yarn.lock
file manually but this should work until a more robust fix is found.So the official (100% working) workaround for now is to downgrade yarn to version 0.24.6
this seems like incopatibility with
webpack
>3.3.0
and@ngtools/webpack
.resolves the issue.
jakeNiemiec comment worked for me too. Is there any fix planned for this breaking change?
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?Finaly makes it work with devDependencies “@angular/cli”: “1.2.6” and dependencies “enhanced-resolve”: “3.3.0” and @angular/*:“^4.3.6”
Also, just to be clear, this is an Angular feature/requirement. Not specific to CLI.
@ThalesMatoso When you reference fields of a component’s class in its template, you are really writing instructions for Angular’s rendering engine to take those values and display them on the DOM. Since the renderer is separate from and external to the component’s class, attempts to access private variables will result in a TypeScript compilation error. Thus any fields in your component’s class which might be touched by external services, such as those referenced in your template or annotated with decorators like
@ViewChild
, must be public.@filipesilva I had a strong suspicion that might be the case; thank you very much for looking into it and confirming, we’ve not tried AOT prior to using
ng
.I suspect we still have a lot of AOT-incompatible code. I have a refactoring task to move this template-less
@Component
to a@Directive
(I’m not even sure why it was written this way).Update for others with a problem like this who still want a prod bundle and who just started using
ng
, the following emits a functional application package:@krjordan I won’t repeat it here, but if you do the edit as I described in #7136 you shouldn’t need the
--pure-lockfile
option.Just as an additional note for people getting the error. It can also be a problem with your code. Please see here for things to check for that will break AOT. Some things will break the build and some will just fail at runtime (from experience)
https://github.com/rangle/angular-2-aot-sandbox
I got especially hit with this yesterday because I ran into this bug AND had one of these problems in my app 😂
Count me in to those who cannot get it to work with
webpack@3.4.0
. Thanks to @jpduckwo for sacrificing his 3 hours to save mine; downgrading towebpack@3.3.0
works great.Yes,
@ngtools/webpack
andwebpack@3.4.0
breaks build also with npm.Shouldn’t we reopen this issue again? Seems, that for many scenarios this is definitely not fixed.
Yarn will keep installing the 3.4 version for package that want it (like webpack which uses a ^ in the version number). The only way I managed to fix it was to modify my yarn.lock by manually changing the version and resolved field for the enhanced-resolve ^3.4.0 entry to point to the 3.3.0 instead.
Tried yarn install as well. It seems it installs correct version 3.3.0 but
ng build --prod
fails.Not using yarn in our project, tried just out of curiosity.
Just tried to build our project with ^1.0.0 which updated to latest 1.2.4 of angular-cli and it fixed the issue.
Thanks guys for a quick turnaround.
Nothing fixes this error for me. Already tried everything writen in this thread.
If anybody did something different please let me know!
@bmcswee 👍 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.
npm list
gave me:works on linux ubuntu 16.04 for me