angular-cli: [AOT] @ngtools/webpack throws "Cannot find module './ngfactory/app/app.module.ngfactory'"


Windows_NT 10.0.10586


I’m trying to integrate @ngtools/webpack into my custom webpack build and is getting Cannot find module './ngfactory/app/app.module.ngfactory' error. The source of the error is here. I’ve managed to suppress the error by disabling this check.

Repro steps.

Github repo:

npm i
npm start

The log given by the failure.

ERROR in ./app/main.aot.ts
Module build failed: Error: D:/Workspace/ngtools-error/app/main.aot.ts (3,34): Cannot find module './ngfactory/app/app.module.ngfactory'.)
    at _transpile (D:\Workspace\ngtools-error\node_modules\@ngtools\webpack\src\loader.js:101:19)
    at D:\Workspace\ngtools-error\node_modules\@ngtools\webpack\src\loader.js:125:26

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 16
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Anyone still getting this?

When you run the ng build in angular 2, latest angular-cli automatically runs with --aot parameter (ahead of time compilation), so it is trying to optimize your code. You are having a package that is not yet compatible for optimizing. So you need update to your packages. Most probably the packages that has forRoot() in your app.module.ts

I recommend to update all packages.

Easy way to update your package is to the use package below, which i got it from


npm install -g npm-check-updates


ncu for display

ncu -u for re-writing your package.json

and run npm install to update your packages

I tryed to run the starting material2 project and I had a similar problem with ngfactory. In main.ts I finded this comment: `

AoT compile. First run ./node_modules/.bin/ngc -p ./src/

` After running that it worked, maybe you can try this.

Check if your tsconfig.json has the following at the root level:

  "angularCompilerOptions": {
    "genDir": "src/ngfactory",
    "entryModule": "./src/app#AppModule"

I had accidentally left that out and for me it fixed the problem.

I have the same error. But if a try to go back to the beta16 I’ve got error: webpack_1.NgcWebpackPlugin is not a constructor TypeError: webpack_1.NgcWebpackPlugin is not a constructor