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?
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.
ng build --env=prod
Just try this instead of ng build --prod
--env=prod and --prod are not the same thing. Please see https://github.com/angular/angular-cli/issues/7113#issuecomment-317472732 for more information about it.
Changing to "@angular/cli": "1.2.4" fixed the problem.
Make sure after changing from 1.0.0 ver to 1.2.4 to npm install before you ng build ...
My version is:
@angular/cli: 1.0.1 node: 6.7.0 os: win32 x64 @angular/common: 4.3.4 @angular/compiler: 4.3.4 @angular/core: 4.3.4 @angular/forms: 4.3.4 @angular/http: 4.3.4 @angular/platform-browser: 4.3.4 @angular/platform-browser-dynamic: 4.3.4 @angular/router: 4.3.4 @angular/cli: 1.0.1 @angular/compiler-cli: 4.3.4 and @mihau1 comment solve my problem : https://github.com/angular/angular-cli/issues/7125#issuecomment-317723824
My original version is 1.2.1 and @angular/cli: 1.2.4 fixed the problem~
This worked for me Step 1: Delete the node_modules folder Step 2: Replace your package.json "devDependencies": with the following;
"@angular/cli": "^1.3.1",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@types/jasmine": "2.5.45",
"@types/jquery": "^3.2.11",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
Step 3; Run npm install
same issue here, but using --env=prod solves the problem, anyways I would like to know what is causing this error
I could fix the issue by running the following commands:
npm install -g @angular/cli@latestnpm install --save-dev @angular/cli@latestrimraf .\node_modules\ncu -unpm installnpm cache clean
Could someone told us about the source of this problem . because if i take my case , the command ng build --prod --aot was working fine . i don't change any thing on my project . and after a while . i have the same error ... updating the angular cli to the version 1.2.4 solve the problem for me . but still not getting what was the problem exactly ? . some help please .
Note: Updating to angular-cli 1.2.4 solved the problem that started this thread for our instance of the installation.
Application development done both on Mac and Windows. Deploying to Apache / Docker containers.
Of course, we also needed to do a fresh npm install.
Thank you @beauxjames , but i found anoher problem when updating to the 1.2.6 . some module in my application are not working . so what you think should i do ? trying to solve this problem and keep the version 1.2.6 of angular or downgrade it to the old version and solve it with another way .
@yassinechabli I was able to solve it in multiple project with CLI 1.2.6 + Error you are getting now might be related to AOT, you can fix it if you follow the guidelines. What error you are getting, may be some one can help. Or search with that error messages separately and fix them.
the problem was about a module (ngx-date-picker) that need to be updated also . i don't know why , but i upgrade to the last version with some modification in my code and it works . thank you @achieverprince .
below command solved my issue npm install [email protected]
removing node_modules and running npm install worked for me.
Sloved !! I had this issue when i was trying the execute ng build -aot command. problem slove for me when i changed the version of "@angular/cli": "1.2.0" to "@angular/cli": "1.3.0",
Sloved !! I had this issue when i was trying the execute ng build -prod command. Problem solved by updating the version of "@angular/cli": "1.0.0" to "@angular/cli": "1.3.0".
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
Could not resolve "./components/template/template.module" from "E:/vat_frontend/src/app/app.module.ts".