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

For now, npm install [email protected] [email protected], will resolve the issues. Txanks

play2web avatar Jul 26 '17 09:07 play2web

@play2web doesn't get resolved if you are using yarn...

BorntraegerMarc avatar Jul 26 '17 09:07 BorntraegerMarc

So the official (100% working) workaround for now is to downgrade yarn to version 0.24.6

BorntraegerMarc avatar Jul 26 '17 12:07 BorntraegerMarc

@BorntraegerMarc Can you please provide a reference to that being the "official" workaround? AFAIK there is no fix, since there's a dependency conflict between @ngtools/webpack and webpack. @ngtools/webpack likely needs to be updated to fix this issue for yarn users.

ferdis avatar Jul 26 '17 14:07 ferdis

OK @uitgewis with "official" I mean it is officially acknowledged (until now) as a bug: https://github.com/yarnpkg/yarn/issues/4024 I don't have anymore info. maybe "official" is a too strong word here 😄 I just know that I had to downgrade to 0.24.6 because nothing else worked

BorntraegerMarc avatar Jul 26 '17 14:07 BorntraegerMarc

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

cebor avatar Jul 26 '17 17:07 cebor

As much as I hate this workaround, you can technically "fix" the yarn.lock file by hand if downgrading yarn is not an option for you. After upgrading your Angular-related dependencies your lockfile should have something like this:

[email protected]:
  version "3.3.0"
  resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
  dependencies:
    graceful-fs "^4.1.2"
    memory-fs "^0.4.0"
    object-assign "^4.0.1"
    tapable "^0.2.5"

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"

Replace that with:

[email protected], enhanced-resolve@^3.0.0:
  version "3.3.0"
  resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
  dependencies:
    graceful-fs "^4.1.2"
    memory-fs "^0.4.0"
    object-assign "^4.0.1"
    tapable "^0.2.5"

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.

zsparal avatar Jul 26 '17 20:07 zsparal

@Gustorn does not work for me, every time i run yarn it adds the wrong entry to yarn.lock again.

Here is my repo with the failing build: https://github.com/cebor/ng2-start

cebor avatar Jul 26 '17 21:07 cebor

@cebor, I should've mentioned, this workaround is for plain CLI projects only (or in other words: it solves the yarn issue but does not solve the webpack issue).

Since you have webpack@^3.4.1 as a dependency you cannot fix your lockfile because the new version explicitly depends on enhanced-resolve@^3.4.0. You can only fix this problem by downgrading to [email protected] first.

zsparal avatar Jul 26 '17 21:07 zsparal

@cebor After doing what @Gustorn suggested, running yarn --pure-lockfile should work. Probably want to make sure to delete your node_modules as well.

krjordan avatar Jul 26 '17 22:07 krjordan

Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'hello/src'

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 😂

jpduckwo avatar Jul 26 '17 22:07 jpduckwo

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

zsparal avatar Jul 26 '17 23:07 zsparal

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 [email protected] (https://github.com/angular/angular-cli/pull/7123) and [email protected] (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?

filipesilva avatar Jul 27 '17 10:07 filipesilva

@filipesilva so for use with angular-cli projects, is adding [email protected] to our package.json enough, or should we also be tying down to [email protected]?

It seems to be fixed in @angular/[email protected] as per comments from others above, however we are not in a position to upgrade to that right now.

What would be the intermediate fix, is first thing mentioned above good enough?

russelltrafford avatar Jul 27 '17 18:07 russelltrafford

FYI I'm still getting this error on just-released 1.2.6 even though it bumps enhanced-resolve to 3.4.1 despite rumours it would work.

I saw a suggestion that this may have something to do with npm 5...somehow? (I did remove my package-lock.json before updating.)

👉 EDIT: See this comment below, it's in fact unrelated.

michaelsanford avatar Jul 27 '17 21:07 michaelsanford

For cli projects

  • yarn 0.24.6
  • enhanced-resolve@3.3.0

For non-cli projects using @ngtools/webpack

  • yarn 0.24.6
  • enhanced-resolve@3.3.0
  • webpack@3.3.0

ghost avatar Jul 27 '17 21:07 ghost

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 allow [email protected] 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, update package.json with [email protected], 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.

filipesilva avatar Jul 28 '17 08:07 filipesilva

Also, when using 1.2.6/1.3.0-rc.3 you shouldn't need to have either enhanced-resolve or webpack in your package.json. It might even break stuff to have webpack in your package.json (https://github.com/angular/angular-cli/issues/7113#issuecomment-318328125).

filipesilva avatar Jul 28 '17 08:07 filipesilva

@ngtools/[email protected] working fine again 👍

jkuri avatar Jul 28 '17 16:07 jkuri

@filipesilva Happy this is solved but as a related issue, could the meaningless error message be fixed so that similar errors in the future gives ANY useful information? (An error referring to a file the developer can not see is not so user friendly).

mmc41 avatar Jul 29 '17 19:07 mmc41