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

Created on 8 Oct 2016  路  19Comments  路  Source: angular/angular-cli

OS?

Windows_NT 10.0.10586

Description.

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: https://github.com/DzmitryShylovich/ngtools-error

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
1 (urgent) bufix

Most helpful comment

Anyone still getting this?

All 19 comments

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.

@DzmitryShylovich what version of @ngtools/webpack are you using?

the latest 1.1.0

Basically I've just copy pasted test app so it might be Windows specific issue.

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

I saw this same error also, when running ng serve -aot However, when I changed a file (added a new <p> ... </p> in app.component.html for instance) the error would not show after the project rebuilt. Making any other change would show the error.. and so on, alternately showing and not showing the error.

I have the same on Windows 10, but also is occurring in my Travis build on mac OS. You can see the full output of that here: https://travis-ci.org/michaelbromley/skqw/jobs/166849701#L466

I just updated to v1.1.0.

2452

It's happening again to me. When I run
> ./node_modules/.bin/ngc -p ./src/
I don't get any error, and all ng-factories are created. But when I run
> ng build

I get the following error:
...\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve\lib\sync.js:33 throw new Error("Cannot find module '" + x + "' from '" + y + "'");

Error: Cannot find module 'ng-factory' from '...\workspaceFrontend
at Function.module.exports [as sync] (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve\lib\sync.js:33:11)
at module.exports (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\resolve-require\lib\index.js:10:24)
at Command.<anonymous> (..\AppData\Roaming\npm\node_modules\ng-cli\lib\index.js:35:5)
at Command.listener (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:301:8)
at emitTwo (events.js:106:13)
at Command.emit (events.js:191:7)
at Command.parseArgs (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:615:12)
at Command.parse (..\AppData\Roaming\npm\node_modules\ng-cli\node_modules\commander\index.js:458:21)
at Object.<anonymous> (C:\Users\Simon\AppData\Roaming\npm\node_modules\ng-cli\lib\index.js:55:9)
at Module._compile (module.js:570:32)

Two days ago I didn't have any problems to create the distribution of the app.
Any idea how to fix this?

NODE v6.9.1
NPM v3.10.6
TSC v2.0.0
[email protected]
[email protected]

I tried in windows and also in linux. In both OS get the same error.

Maybe this is a different issue?

>npm start works fine
>npm build doesn't do anything , I think because ng build crashes

Same as @sdeuvarow for me... in my case from ubuntu 16.04

I had a conflict with "ng-cli" package. Removing it and reinstall angular-cli fix the issue.

Anyone still getting this?

I'm still seeing this issue with @ngtools/webpack 1.2.3. Interestingly enough it works if I have the site open before running 麓npm start麓 but then it imediatly recompiles and throws the error.

Closing this as obsolete. Please provide a git repo that we can try to reproduce.

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 http://stackoverflow.com/questions/36597780/how-do-i-correctly-upgrade-angular-2-npm-to-the-latest-version

Install

npm install -g npm-check-updates

Usage

ncufor display

ncu -u for re-writing your package.json

and run npm installto update your packages

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.

@18steps that didn't work for me 馃樋

I was trying to follow the docs for aot compilation, and the only difference I have is I want JIT to be the default main.ts and AOT be opt in with main-aot.ts (so I can bundle scripts just for production, automatically, with a postinstall script or whatever).

My aot folder output is also one directory level above my src directory -

  "angularCompilerOptions": {
    "genDir": "../aot",
    "basePath": "./src/", // this doesn't change anything :c
    "entryModule": "./src/app#AppModule" // this didn't help either :c
  }

And inside that aot folder it doesn't include the compiled main-aot.ts file, it just has app folder with broken .ngfactory.ts and .ngsummary.ts files, all of which have ts errors because they're import urls are wrong.

Can I not have my aot output be somewhere else? genDir is constrained?

Maybe #1465 would help me actually.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings