angular: Can't resolve *.ngfactory.js on AOT serve after update to Angular 6.1

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

After updating to angular 6.1.3 with ng update when I serve my project with AOT (i need it) everything works fine but after a refresh (after a save for example) i get a lot of errors like that :

ERROR in ./src/app/common/modules/search/city-input/city-input.component.ngfactory.js
Module not found: Error: Can't resolve '@angular/material/autocomplete.ngfactory' in '/mnt/d/Upstream/chat_fronts_v3/src/app/common/modules/search/city-input'

And crash

Expected behavior

That should not append just like before

Minimal reproduction of the problem with instructions

  • create a new project with routing
  • ng serve --aot
  • ctrl +s on any project file
  • ERROR in ./src/app/app.module.ngfactory.js Module not found: Error: Can't resolve '@angular/router.ngfactory' in '/mnt/d/Sites/test-app/src/app'

What is the motivation / use case for changing the behavior?

Angular become unusable after that

Environment


Angular version: 6.1.3


Browser:
- [x] Chrome (desktop) version 67.0.3396.99
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.1.3
Node: 10.8.0
OS: linux x64
Angular: 6.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.3
@angular-devkit/build-angular     0.7.3
@angular-devkit/build-optimizer   0.7.3
@angular-devkit/build-webpack     0.7.3
@angular-devkit/core              0.7.3
@angular-devkit/schematics        0.7.3
@angular/cdk                      6.4.3
@angular/cli                      6.1.3
@angular/material                 6.4.3
@ngtools/webpack                  6.1.3
@schematics/angular               0.7.3
@schematics/update                0.7.3
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 57
  • Comments: 56 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I am having the same issue. I had the issue with angular cli 6.0.8 and also after a upgrade to 6.1.3 . First of all I thought it was because I changed the project structure a bit from what angular cli generated. But then I just tried it out with an new empty angular cli project and I got the same error.

Steps to reproduce:

  • Create a new project using ng new (I used following command: ng new poc --style=scss --minimal --routing)
  • Go to the folder
  • Start angular with ng serve --aot
  • Change a file, for example app.component.ts by adding a new line or similar and save.

I get following error as result

ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve '@angular/router.ngfactory' in 'C:\dev\private-tools\hive-platform\poc2\src\app'

Don’t know if it is important, but I am using yarn as package manager for node.

Can confirm this error (the @angular/router.ngfactory one). Interestingly it only appears on the second incremental rebuild, so the initial dev build works, first src file save works, saving the file again … BOOM.

@sty1iss @MikaStark downgrading angular or cli is useless. you need to use this: npm i -S @angular/compiler@6.1.1 @angular/compiler-cli@6.1.1

to pin these two compiler components at 6.1.1.

Comes only with the second or consecutive incremental builds

Workaround: downgrade and hard code all @angular/* packages (excluding cli, that one does not matter) to 6.1.1 (no ~ or ^), the bug was most likely introduced in 6.1.2 (https://github.com/angular/angular/pull/25335).

@toverux’s workaround worked for me as well. Pin angular compiler and compiler-cli to 6.1.1.

$ npm i -S @angular/compiler@6.1.1 @angular/compiler-cli@6.1.1

Had no need to pin other packages than @angular/compiler and @angular/compiler-cli (don’t know which one is the faulty one, but I’ll keep them in sync). Regular Angular packages, including @angular/cli, seem to be upgraded safely.

⚡ yarn outdated
yarn outdated v1.9.4
Package               Current Wanted Latest Package Type    URL                                                                 
@angular/compiler     6.1.1   6.1.1  6.1.2  dependencies    https://github.com/angular/angular#readme                           
@angular/compiler-cli 6.1.1   6.1.1  6.1.2  dependencies    https://github.com/angular/angular/tree/master/packages/compiler-cli
typescript            2.9.2   2.9.2  3.0.1  devDependencies http://typescriptlang.org/ 

SOLVED!

If you have this type of error probably you have upgraded from Angular 5 to 6 or 7.

Replace "rootDir": "./src", in your tsconfig.json file to "rootDir": "./", or just remove this parameter completely.

Fixed in Angular 6.1.6

Fixed for me in Angular 6.1.6. Thanks!

@MikaStark yeah, I may switch to angular’s i18 utils, until now it was working for me, so I did not bother… here is what I found until now: in webpack.config.js when I change

new AngularCompilerPlugin({
        tsConfigPath: './tsconfig.json',
        entryModule: './src/app/app.module.ts#AppModule',
        sourceMap: true
      })

to

new AngularCompilerPlugin({
        tsConfigPath: './tsconfig.json',
        entryModule: './src/app/app.module#AppModule',
        sourceMap: true
      })

the error is gone. So I have erased .ts. I don’t know how crucial is to have it there, through I still cannot run my app because of other issues…

@sten82 three reasons:

  • aot is now the default, I believe it means the recommended option
  • the generated code is more similar to the production code, less like to hit unforeseen bugs
  • you can use one less polyfill

Issue still exists.

Angular — 7.2.5 Angular CLI — 7.3.2 TypeScript — 3.2.4

Downgrading in any case is a regressive attitude. This problem must be fixed without workaround.

@zaphyre this is not only relied to router but ALL modules. And yes it only happened after second watch rebuild. The only common point is AOT.

Issue fixed: Just update your cli and core to the latest version. ng update @angular/cli ng update @angular/core

Well, this happens if i run ng build with "aot": true — if i set it false everything will be fine… but i need AOT, i cannot turn it off.

I have the @angular/cli v6.2.5 and created a new project, served it with the --aot flag. I still experience this problem…

Fixed for me in Angular 6.1.7 Thanks!

I would say, if a piece of software is fragile and touchy, it should be made less so. Error messages should describe what caused the problem. That fact that “every Angular dev knows” the message means only that happens more often than it should. An Angular evangelist responded to some tweet of mine a while ago that the team is trying to make error messages more comprehensible and actionable. With all due respect, they could start with this one.

Bob

On Fri, Sep 7, 2018 at 9:13 PM Morgan Touverey-Quilling < notifications@github.com> wrote:

@rtm https://github.com/rtm I don’t have this issue anymore after upgrading. It really looks like it’s been fixed. This is a pretty generic error message that every Angular dev knows. Maybe it’s coming from elsewhere. The AoT compiler does good work but it’s also pretty fragile and touchy 😃

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular/issues/25424#issuecomment-419480497, or mute the thread https://github.com/notifications/unsubscribe-auth/AABfR-QtgVABEqNxBTR133WqmUqRzurbks5uYpQqgaJpZM4V4Ehv .

Looks like this is fixed in Angular v6.1.6.

Here is one more you can add to the list… started getting the errors when updated to latest CLI 😛