Search code examples
angularangular-cliangular-cli-v6

Angular 6's ng serve cannot find @angular/router.ngfactory without re-running ng serve


When I modify anything in my app, up until recently the ng serve auto-refreshing of the code to the browser was working (for the most part) perfectly. Now, however, it is not working at all, with any change triggering a re-compile, which always outputs the following error:

ERROR in ./src/app/msys-modules/main/msys-submodules/manage-views/manage-views.module.ngfactory.js
Module not found: Error: Can't resolve '@angular/router.ngfactory'

However, if I Control-C out of ng serve and re-run it, it runs perfectly well and ends with Compiled succesfully.

I've tried to run npm install again, delete the node_modules folder and then run npm install again, but the problem remains. I'm a bit lost as to where else I can search for the failing module; and why does it work fine if I just recompile it "from scratch"? It's much more time-consuming to have to re-run ng serve every time.

The Angular version info is:

Angular CLI: 6.1.5
Node: 8.11.2
OS: win32 x64
Angular: 6.1.4

Solution

  • Update Angular core to the latest version:

    ng update @angular/core