angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open DzmitryShylovich opened this issue 10 years ago • 19 comments

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

DzmitryShylovich avatar Oct 08 '16 10:10 DzmitryShylovich

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.

david1880 avatar Oct 10 '16 08:10 david1880

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

filipesilva avatar Oct 10 '16 10:10 filipesilva

the latest 1.1.0

DzmitryShylovich avatar Oct 10 '16 10:10 DzmitryShylovich

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

DzmitryShylovich avatar Oct 10 '16 11:10 DzmitryShylovich

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

Gamblt avatar Oct 11 '16 10:10 Gamblt

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.

jtsom avatar Oct 11 '16 10:10 jtsom

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.

michaelbromley avatar Oct 11 '16 20:10 michaelbromley

#2452

delagen avatar Oct 12 '16 04:10 delagen

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

sdeuvarow avatar Oct 31 '16 03:10 sdeuvarow

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

fcrocce avatar Oct 31 '16 19:10 fcrocce

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

sdeuvarow avatar Oct 31 '16 20:10 sdeuvarow

Anyone still getting this?

Meligy avatar Jan 16 '17 19:01 Meligy

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.

zoehneto avatar Jan 17 '17 17:01 zoehneto

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

hansl avatar Feb 03 '17 20:02 hansl

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

ncu for display

ncu -u for re-writing your package.json

and run npm install to update your packages

karthikeyanVK avatar Mar 10 '17 12:03 karthikeyanVK

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 avatar May 25 '17 18:05 18steps

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

snewell92 avatar Jun 27 '17 16:06 snewell92

Maybe #1465 would help me actually.

snewell92 avatar Jun 27 '17 16:06 snewell92

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.