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 [email protected] .
@benelliott good point.
@lsunkara AFAIK that will result in a non-aot build which might not be desirable for everyone.
@warmans is correct. Please see https://github.com/angular/angular-cli/wiki/build#--dev-vs---prod-builds for effect of the --prod flag.
@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.
@warmans, I agree, ng build --env=prod is not desirable. Pinning to enhanced-resolve to 3.3.0 only works. Thanks.
Relevant issues in the enhance-resolve repo:
- https://github.com/webpack/enhanced-resolve/issues/98 by @H--o-l
- ~~https://github.com/webpack/enhanced-resolve/issues/107~~ closed by @filipesilva in favor of https://github.com/webpack/enhanced-resolve/issues/98
Changes since 3.3.0.
Nothing fixes this error for me. Already tried everything writen in this thread.
If anybody did something different please let me know!
@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:
- Remove every reference to
enhanced-resolvefrom yourpackage.json(if you already have some from other workarounds) - Run the command:
npm i -DE [email protected](-DEshould work consistently between npm4 and npm5) - (Optional) Delete your
node_modulesfolder to verify that it works with a clean install 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.
@Gustorn's that's a very good step by step guide, thanks!
@gustorn I also had to clear my npm cache to get the right version.
@warmans Did you pass the -E flag? The npm cache shouldn't matter if you ask for a specific version of the package (or if it does get it wrong I'd argue it's a bug in npm).
@HirenParekh It's because @ngtools/webpack does not lock lock the version of enhanced-resolve. If you take a look at its package.json file from the 1.1.1 release you'll see that the version is ^3.1.0. npm, on fresh installs, will install the newest, semver-compatible version of the package, which in this case is the breaking 3.4.0 version.
Edit: apparently the second comment I was replying to was deleted. Since the explanation might be useful for someone, the question was basically:
Why doesn't downgrading to
@angular/[email protected]solve the issue?
@filipesilva Could this be related to the vue-cli AoT issue pointed out by @yyx990803
https://github.com/webpack/enhanced-resolve/commit/03ef8f2b8d25bc976993eade7b1ed9caa2c7d0e1#commitcomment-23261583
Edit: To be clear, fixes for https://github.com/webpack/enhanced-resolve/pull/100 do not fix this issue.
npm inpm i [email protected]
1.npm clean cache 2. Delete node_modules 3. Add "enhanced-resolve": "3.3.0" in your package.json 4. run npm install then test the command "ng build --prod"
Resolved the issue for me.
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.
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.
@filipesilva using version 1.2.4 on osx, installed with yarn has not worked
and with version 1.3.0-rc.1 I see:
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/john/Workspace/tcabs2/ui/src'
resolve './$$_gendir/app/app.module.ngfactory' in '/Users/john/Workspace/tcabs2/ui/src'
using description file: /Users/john/Workspace/tcabs2/ui/package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /Users/john/Workspace/tcabs2/ui/package.json (relative path: ./src)
using description file: /Users/john/Workspace/tcabs2/ui/package.json (relative path: ./src/$$_gendir/app/app.module.ngfactory)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory.js doesn't exist
as directory
/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory doesn't exist
[/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory]
[/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory.ts]
[/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory.js]
[/Users/john/Workspace/tcabs2/ui/src/$$_gendir/app/app.module.ngfactory]
@ ./src/main.ts 3:0-74
@ multi ./src/main.ts
version 1.2.4 works with an npm install, not with a yarn install
@mildfuzz try removing your yarn.lock, it's probably keeping [email protected] around. On the next yarn, it will be rebuilt.