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

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?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 64
  • Comments: 67 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I did a successful ng build -prod a couple of hours ago, but now I get the same error without changing nothing to my project.

updating to @angular/cli 1.2.4 and the other packages to the latest version solved the issue for me.

Updating to @angular-cli: 1.2.4 fixed the issue for me.

@angular/cli: 1.2.4 fix the problem

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

npm install enhanced-resolve@3.3.0 --save; ng build --prod --aot; (result: now everything is OK)

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

None of the package updating worked for me but adding enhanced-resolve: 3.3.0 did. See #4551

Change your package.json to zone.js: 0.8.14. Delete node_modules folder and run npm install again.

Updating to @angular/cli@1.2.4 and zone.js@0.8.14 Then remove node_modules directory npm cache clear npm install fixed the issue with ng build --prod

@angular/cli: 1.2.4 fixed the problem for me also - this on VSTS Hosted

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

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.

This command is 100% work for solving this problem. npm install enhanced-resolve@3.3.0

ng build --env=prod

Just try this instead of ng build --prod

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.

Updating to @angular/cli: 1.2.4 also fixed the problem for me.

Trying to build AOT but still unsuccessful! Even tried #7113 solution. But still error persists.kindly help Thanks! @filipesilva @Brocco

current cli version installed: screenshot_1

Error screen shot screenshot_2

Happens for me too. These are the versions of my project:

@angular/cli: 1.1.3
node: 6.11.0
os: darwin x64
@angular/animations: 4.2.4
@angular/common: 4.2.4
@angular/compiler: 4.2.4
@angular/core: 4.2.4
@angular/forms: 4.2.4
@angular/http: 4.2.4
@angular/platform-browser: 4.2.4
@angular/platform-browser-dynamic: 4.2.4
@angular/router: 4.2.4
@angular/cli: 1.1.3
@angular/compiler-cli: 4.2.4
@angular/language-service: 4.2.4

None of the solutions worked for me, because the issue was about memory. Maybe the command below could work for those who couldn’t find a solution. This solved the issue in my case.

node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod

The fix is only working on MacOS for me. I still get the error in my CI environment which runs the build --prod on a node:8.2 docker image based on debian. I updated to @angular/cli 1.2.4 and also fixed the version of enhanced-resolve to 3.3.0.

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.

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?

I’m getting the same error too. Updating zone.js did not work for me.