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

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'

Open marciomsm opened this issue 9 years ago • 67 comments

I am getting ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' when I run ng build --prod, but if I run the command ng build --env=prod I get success.

Do we have any differences between these commands?

marciomsm avatar Jul 24 '17 18:07 marciomsm

@atiris Are you running on linux or windows? For some reason enhanced-resolve: 3.3.0 fixes it for my on windows, but not on linux. It's the same version of npm and node on both machines.

flauc avatar Jul 25 '17 09:07 flauc

@atiris Have you cleared your npm cache, and removed the angular-cli global package?

PierreDuc avatar Jul 25 '17 09:07 PierreDuc

@PierreDuc I do my complete procedure again just now:
cd <project>;
delete node_modules;
delete package-lock.json;
npm uninstall @angular/cli -g;
npm cache clean --force; (last time I run only npm cache verify)
npm install @angular/cli -g;
npm cache verify;
close / open console;
cd <project>;
npm install;
ng --version; (result: 1.2.4)
ng build --aot; (result: many errors type Can't resolve './$$_gendir/app/app.module.ngfactory') checked package.json --> dependencies already contains "enhanced-resolve": "^3.3.0" but I run also next command npm install [email protected] --save; ng build --aot; (result: now everything is OK) ng build --aot --locale sk --i18n-file locale/messages.sk.xmb --i18n-format xmb; (result: again the same error, but only one)

ERROR in Unsupported
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '<project>\src'
 @ ./src/main.ts 3:0-74
 @ multi ./src/main.ts

@flauc I run it on windows. My actual versions:

@angular/cli: 1.2.4, node: 8.1.3, npm: 5.3.0, os: win32 x64
@angular/animations, @angular/common, @angular/compiler, @angular/core, @angular/forms,
@angular/http, @angular/platform-browser, @angular/platform-browser-dynamic,
@angular/platform-server, @angular/router, @angular/upgrade, @angular/compiler-cli,
@angular/language-service: 4.3.1

atiris avatar Jul 25 '17 09:07 atiris

@filipesilva

I am also having the same problem,

Tried all solutions mentioned above

The project is newly generated by the command

ng new my-prj --skip-install --skip-git -dir my-prj --style scss --routing

ankeshdave avatar Jul 25 '17 09:07 ankeshdave

@angular/cli: 1.2.4 fix the problem, but can't ng build --prod --aot, I got

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

The last fine build was done before angular 4.3

x-c4mp3r avatar Jul 25 '17 10:07 x-c4mp3r

Same issue here... only fix for me seems to be changing build script to use --env=prod instead of --prod. Updating @angular/cli and other packages didn't make a difference.

frednomoon avatar Jul 25 '17 11:07 frednomoon

Heya, please see https://github.com/angular/angular-cli/issues/7113#issuecomment-317523744 for this issue.

filipesilva avatar Jul 25 '17 11:07 filipesilva

Updating to @angular/[email protected] and [email protected] Then remove node_modules directory npm cache clear npm install fixed the issue with ng build --prod

nourson avatar Jul 25 '17 11:07 nourson

Hi @filipesilva, did you see that I used the latest angular cli 1.2.4 for test when I got this error here https://github.com/angular/angular-cli/issues/7125#issuecomment-317683022 ? How this https://github.com/angular/angular-cli/issues/7113#issuecomment-317523744 can help me, if I already use angular/[email protected]? Or changing angular cli is not the only thing i have to do according your message? I guess I just do not know what to do. Thank you in advance for the answer.

atiris avatar Jul 25 '17 11:07 atiris

@atiris it looks like there might be another problem, related to --i18n only. Can you open a new issue where we can track it?

filipesilva avatar Jul 25 '17 11:07 filipesilva

@filipesilva sure, here: https://github.com/angular/angular-cli/issues/7133

atiris avatar Jul 25 '17 12:07 atiris

I can confirm that ng new project-name problem with "$$_gendir/app/app.module.ngfactory" can be resolved by:

npm install [email protected] --save; ng build --prod --aot; (result: now everything is OK)

also ng build --prod its not this same as ng build --env=prod

mihau1 avatar Jul 25 '17 12:07 mihau1

Updating to @angular/cli: 1.2.4 worked for me!

andrewrady avatar Jul 25 '17 20:07 andrewrady

We don't use @angular-cli (using webpack directly) and the same problem started happening last night. upgrading zone.js didn't help. Anybody have any idea?

lroitman avatar Jul 25 '17 21:07 lroitman

@Iroitman try to delete the node_modules folder and package-lock.json file and then run npm install again!

marciomsm avatar Jul 25 '17 21:07 marciomsm

@marciomsm I installed "enhanced-resolve": "3.3.0", and it helped. Note that "enhanced-resolve": "^3.3.0" failed (it picked 3.4.1, and this caused failure)

lroitman avatar Jul 25 '17 22:07 lroitman

I also got this issue with @angular/cli 1.2.4. After working around, I found the reason from webpack package. You must delete folder enhanced-resolve in webpack/node_modules and run 'ng build --prod' again. It works with me. I think webpack is using the latest version 3.4.1 which does not work with Angular CLI.

Note: This is only temperate solution. We should wait for a fix of Angular CLI to force to use enhanced-resolve 3.3.0.

leovo2708 avatar Jul 26 '17 04:07 leovo2708

Updating to @angular/cli: 1.2.4 worked for me!

Make sure you are updating @angular/* to latest version ^4.2.4 Then delete node_modules and do npm install

achieverprince avatar Jul 26 '17 06:07 achieverprince

I found there are difference between yarn & npm. With npm, webpack is installed but no dependency 'enhanced-resolve' is included With yarn, webpack is installed but dependency 'enhanced-resolve' 3.4.1 is included When run 'ng build --prod' with yarn packages, 'enhanced-resolve' 3.4.1 causes this issue.

leovo2708 avatar Jul 26 '17 06:07 leovo2708

#7136

leovo2708 avatar Jul 26 '17 06:07 leovo2708