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

AOT build fails

Open adwd opened this issue 9 years ago • 173 comments

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

adwd avatar Jul 24 '17 10:07 adwd

good point. Hmmm, curious

mildfuzz avatar Jul 24 '17 22:07 mildfuzz

Is there any workaround to use yarn + [email protected]?

cebor avatar Jul 24 '17 22:07 cebor

@cebor I'm in the same situation but haven't found a fix yet.

coryrylan avatar Jul 24 '17 22:07 coryrylan

I'm still seeing this fail on my linux env:

$ng -v @angular/cli: 1.2.4 node: 6.11.1 os: linux x64 @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.4 @angular/compiler-cli: 4.3.1 [root@4bc7c5f8560c]# yarn list enhanced-resolve yarn list v0.27.5 ├─ [email protected] └─ [email protected] └─ [email protected] Done in 0.62s.

OS X & Linux have version matches for both @angular/cli && enhances resolve. However, running on my alpine docker container i get:

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

The OS X version builds with no issues

rightisleft avatar Jul 25 '17 00:07 rightisleft

I'm seeing a different, maybe related issue. I upgraded to @angular/[email protected] based on this thread. When I do an AOT build without the --prod flag, everything is fine. It fixes the webpack loading issue. Though nothing is cache busted or minified (as expected).

$ ng build -aot -bh /app/ -d /app/
 12% building modules 24/26 modules 2 active ...dh/code/skyl-sam/gui/src/polyfills.tsThe final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string
Hash: dccdd84edb379b90050e
Time: 18188ms
chunk    {0} common.bundle.js, common.bundle.js.map (common) 225 kB {8} [initial] [rendered]
chunk    {1} 1.chunk.js, 1.chunk.js.map 158 kB {2} {4} [rendered]
chunk    {2} 2.chunk.js, 2.chunk.js.map 22.8 kB {1} {4} [rendered]
chunk    {3} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 305 kB {8} [initial] [rendered]
chunk    {4} main.bundle.js, main.bundle.js.map (main) 206 kB {7} [initial] [rendered]
chunk    {5} styles.bundle.js, styles.bundle.js.map (styles) 12.8 kB {8} [initial] [rendered]
chunk    {6} scripts.bundle.js, scripts.bundle.js.map (scripts) 935 bytes {8} [initial] [rendered]
chunk    {7} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.39 MB [initial] [rendered]

However, an AOT build with --prod errors out in the browser. It tells me that a chunk could not be found.

$ ng build -aot -bh /app/ -d /app/ --prod
 12% building modules 20/22 modules 2 active ...dh/code/skyl-sam/gui/src/polyfills.tsThe final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string
Hash: 087aa24978df80ff0791
Time: 31614ms
chunk    {0} common.c748e79cd1f1548103ca.bundle.css (common) 64.2 kB {8} [initial] [rendered]
chunk    {1} 1.25adab460fca740132f8.chunk.js 156 kB {2} {4} [rendered]
chunk    {2} 2.d8720a9ef943f0c023dd.chunk.js 22.8 kB {1} {4} [rendered]
chunk    {3} polyfills.ff68bf59b00f20dd55fa.bundle.js (polyfills) 305 kB {8} [initial] [rendered]
chunk    {4} main.84addcca1f874b2e3beb.bundle.js (main) 204 kB {7} [initial] [rendered]
chunk    {5} scripts.8e25fcd212b7caba6537.bundle.js (scripts) 935 bytes {8} [initial] [rendered]
chunk    {6} styles.5d90f8fb1f36b9f8617d.bundle.css (styles) 69 bytes {8} [initial] [rendered]
chunk    {7} vendor.32a6e9e7149831c7fbfc.bundle.js (vendor) 2.39 MB [initial] [rendered]
chunk    {8} inline.1170c1e8a9ba9c0dfcf5.bundle.js (inline) 0 bytes [entry] [rendered]

Error in the browser

ERROR Error: Uncaught (in promise): Error: Loading chunk 0 failed.
Error: Loading chunk 0 failed.
    at HTMLScriptElement.n (inline.1170c1e….bundle.js:1)
    at HTMLScriptElement.o (polyfills.ff68bf5….bundle.js:1)
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at Object.onInvokeTask (vendor.32a6e9e….bundle.js:1)
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at r.runTask (polyfills.ff68bf5….bundle.js:1)
    at e.invokeTask [as invoke] (polyfills.ff68bf5….bundle.js:1)
    at h (polyfills.ff68bf5….bundle.js:1)
    at HTMLScriptElement.d (polyfills.ff68bf5….bundle.js:1)
    at HTMLScriptElement.n (inline.1170c1e….bundle.js:1)
    at HTMLScriptElement.o (polyfills.ff68bf5….bundle.js:1)
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at Object.onInvokeTask (vendor.32a6e9e….bundle.js:1)
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at r.runTask (polyfills.ff68bf5….bundle.js:1)
    at e.invokeTask [as invoke] (polyfills.ff68bf5….bundle.js:1)
    at h (polyfills.ff68bf5….bundle.js:1)
    at HTMLScriptElement.d (polyfills.ff68bf5….bundle.js:1)
    at a (polyfills.ff68bf5….bundle.js:1)
    at a (polyfills.ff68bf5….bundle.js:1)
    at polyfills.ff68bf5….bundle.js:1
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at Object.onInvokeTask (vendor.32a6e9e….bundle.js:1)
    at t.invokeTask (polyfills.ff68bf5….bundle.js:1)
    at r.runTask (polyfills.ff68bf5….bundle.js:1)
    at o (polyfills.ff68bf5….bundle.js:1)
    at e.invokeTask [as invoke] (polyfills.ff68bf5….bundle.js:1)
    at h (polyfills.ff68bf5….bundle.js:1)
_ @ vendor.32a6e9e….bundle.js:1

So, looks like it was expecting the chunk "0.84a03cc88aee47079f58.chunk.js" to be generated but it was not. Has anyone seen something like this? Would really appreciate any help here. Thanks!

samridh90 avatar Jul 25 '17 01:07 samridh90

That issue is really annoying and took me some hours. But npm install [email protected] worked fine for me on windows, no further delete or clean needed. Thanks for that helpful hint!

Chris380 avatar Jul 25 '17 06:07 Chris380

You can update your package.json with @angular/cli ~1.2.0. It will update to latest 1.2.4 and you don't need to hack-install it

sickelap avatar Jul 25 '17 07:07 sickelap

@filipesilva so I am not using [email protected]

yarn list webpack shows [email protected], which has "enhanced-resolve": "^3.0.0",, so this would update to 3.4.1 when executed, no?

Even at [email protected] we are not pinned, we have "enhanced-resolve": "^3.3.0",

mildfuzz avatar Jul 25 '17 08:07 mildfuzz

@filipesilva

$ yarn list enhanced-resolve
yarn list v0.27.5
├─ @ngtools/[email protected]
│  └─ [email protected]
└─ [email protected]
Done in 0.83s.
$ yarn why enhanced-resolve
yarn why v0.27.5
[1/4] Why do we have the module "enhanced-resolve"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info This module exists because "webpack" depends on it.
info Disk size without dependencies: "196kB"
info Disk size with unique dependencies: "328kB"
info Disk size with transitive dependencies: "848kB"
info Number of shared dependencies: 10
Done in 0.84s.
$ yarn list webpack
yarn list v0.27.5
└─ [email protected]
Done in 0.83s.

My entire package.json here: https://gist.github.com/ryzy/aa422bc587c6858207caa55aa66c82db

ryzy avatar Jul 25 '17 09:07 ryzy

Does anybody have a fix for yarn users? I'm still experiencing the error. Even tried to downgrade from @angular/cli": "1.2.4 to @angular/cli": "1.2.3 because there enhanced-resolve seems to have released a fix: https://github.com/webpack/enhanced-resolve/releases/tag/v3.4.1

But I'm still experiencing the error. With ether version.

yarn list enhanced-resolve
yarn list v0.27.5
└─ [email protected]
Done in 1.26s.
yarn why enhanced-resolve
yarn why v0.27.5
[1/4] Why do we have the module "enhanced-resolve"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info This module exists because "@angular/cli#@ngtools/webpack" depends on it.
Done in 2.81s.

BorntraegerMarc avatar Jul 25 '17 09:07 BorntraegerMarc

@BorntraegerMarc adding enhanced-resolve locked to 3.3.0 into package.json fixed the issue with yarn

sickelap avatar Jul 25 '17 09:07 sickelap

@sickelap I'm not using yarn's flat architecture. It's not possible because of external reasons. Or do you mean something else? And I don't think it's possible to add a single dependency to the resolutions right?

BorntraegerMarc avatar Jul 25 '17 09:07 BorntraegerMarc

@BorntraegerMarc for some reason yarn installs enhanced-resolve as root dependency, although it's updated to correct version for webpack dep. So to fix it just add "enhanced-resolve": "3.3.0" into your package.json devDependencies and it should be fixed at least for now.

sickelap avatar Jul 25 '17 09:07 sickelap

@sickelap I added "enhanced-resolve": "3.3.0", to the devDependencies and ran yarn cache clean and yarn but I still have the same error. I also deleted the yarn.lock file.

in the yarn.lock file I still see the entry:

enhanced-resolve@^3.0.0:
  version "3.4.1"
  resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
  dependencies:
    graceful-fs "^4.1.2"
    memory-fs "^0.4.0"
    object-assign "^4.0.1"
    tapable "^0.2.7"

BorntraegerMarc avatar Jul 25 '17 10:07 BorntraegerMarc

ERROR in Type PropertiesViewComponent in /media/vimal/personal/future/dar-wepapp/src/app/properties-view/properties-view.component.ts is part of the declarations of 2 modules: AppModule in /media/vimal/personal/future/dar-wepapp/src/app/app.module.ts and loginModule in /media/vimal/personal/future/dar-wepapp/src/app/login/login.module.ts! Please consider moving PropertiesViewComponent in /media/vimal/personal/future/dar-wepapp/src/app/properties-view/properties-view.component.ts to a higher module that imports AppModule in /media/vimal/personal/future/dar-wepapp/src/app/app.module.ts and loginModule in /media/vimal/personal/future/dar-wepapp/src/app/login/login.module.ts. You can also create a new NgModule that exports and includes PropertiesViewComponent in /media/vimal/personal/future/dar-wepapp/src/app/properties-view/properties-view.component.ts then import that NgModule in AppModule in /media/vimal/personal/future/dar-wepapp/src/app/app.module.ts and loginModule in /media/vimal/personal/future/dar-wepapp/src/app/login/login.module.ts.

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/media/vimal/personal/future/dar-wepapp/src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts

vimalraj9423 avatar Jul 25 '17 10:07 vimalraj9423

wonderful idea

drawcall avatar Jul 25 '17 10:07 drawcall

@BorntraegerMarc @mildfuzz I don't know what's wrong with yarn resolutions but I can have a go at it myself. Can you provide me with a package.json that I can tinker with?

@ryzy I tried your package.json and this is what I got:

kamik@T460p MINGW64 D:/sandbox/tmp
$ yarn --version
0.24.6

kamik@T460p MINGW64 D:/sandbox/tmp
$ yarn
yarn install v0.24.6
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 81.84s.

kamik@T460p MINGW64 D:/sandbox/tmp
$ yarn list enhanced-resolve
yarn list v0.24.6
└─ [email protected]
Done in 0.86s.

kamik@T460p MINGW64 D:/sandbox/tmp
$ yarn why enhanced-resolve
yarn why v0.24.6
[1/4] Why do we have the module "enhanced-resolve"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info Reasons this module exists
   - "@angular/cli#@ngtools/webpack" depends on it
   - "@angular/cli#

So atm it seems to me that v0.27.5 doesn't resolve dependencies properly while v0.24.6 does.

filipesilva avatar Jul 25 '17 11:07 filipesilva

@filipesilva thx for the reply. I'm running yarn v0.27.5 so maybe that is the problem...

Here is my package.json:

{
    "name": "x",
    "version": "1.0.0",
    "engine": {
        "node": "0.10.x",
        "npm": "2.1.x"
    },
    "homepage": "komed-health.com",
    "scripts": {
        "build:prod": "ng build --prod"
    },
    "dependencies": {
        "@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/platform-server": "4.3.1",
        "@angular/router": "4.3.1",
        "@angular/service-worker": "1.0.0-beta.16",
        "@codebakery/origami": "1.2.3",
        "@types/socket.io-client": "1.4.29",
        "angular-translator": "2.2.0",
        "check-browser": "0.1.7",
        "classlist.js": "1.1.20150312",
        "core-js": "2.4.1",
        "intl": "1.2.5",
        "ngx-auto-unsubscribe": "1.0.0",
        "rollup": "0.45.2",
        "rollup-plugin-commonjs": "8.0.2",
        "rollup-plugin-node-resolve": "3.0.0",
        "rxjs": "5.4.2",
        "tributejs": "2.3.7",
        "zone.js": "0.8.14"
    },
    "devDependencies": {
        "@angular/cli": "1.2.4",
        "@angular/compiler-cli": "4.3.1",
        "@types/jasmine": "2.5.53",
        "browserstack-local": "1.3.0",
        "codelyzer": "3.1.2",
        "cpr": "2.2.0",
        "db-migrate": "0.10.0-beta.21",
        "db-migrate-mongodb": "1.2.2",
        "enhanced-resolve": "3.3.0",
        "jasmine-core": "2.6.4",
        "jasmine-spec-reporter": "4.1.1",
        "karma": "1.7.0",
        "karma-chrome-launcher": "2.2.0",
        "karma-cli": "1.0.1",
        "karma-coverage-istanbul-reporter": "1.3.0",
        "karma-jasmine": "1.1.0",
        "karma-jasmine-html-reporter": "0.2.2",
        "polymer-cli": "1.3.1",
        "protractor": "5.1.2",
        "rimraf": "2.6.1",
        "ts-node": "3.2.1",
        "tslint": "5.5.0",
        "typescript": "2.4.2"
    }
}

BorntraegerMarc avatar Jul 25 '17 11:07 BorntraegerMarc

@BorntraegerMarc perhaps try explicitly specifying "enhanced-resolve": "3.3.0" under dependencies as well as devDependencies

bmcswee avatar Jul 25 '17 12:07 bmcswee

@bmcswee that also didn't work...

BorntraegerMarc avatar Jul 25 '17 12:07 BorntraegerMarc