ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
OS?
Windows 7 64 bit
Versions.
@angular/cli: 1.0.0-beta.30 node: 7.4.0 os: win32 x64 @angular/common: 2.4.6 @angular/compiler: 2.4.6 @angular/core: 2.4.6 @angular/forms: 2.4.6 @angular/http: 2.4.6 @angular/platform-browser: 2.4.6 @angular/platform-browser-dynamic: 2.4.6 @angular/router: 3.4.6 @angular/cli: 1.0.0-beta.30 @angular/compiler-cli: 2.4.6
Repro steps.
App started using angular cli
The log given by the failure.
This is from my command line:
ERROR in Unexpected value 'null' declared by the module 'AppModule in C:/Users/T haniri/Desktop/freecodecamp/myroute/src/app/app.module.ts'
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Users\Thaniri\Desktop\freecodecamp\myroute\src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts
Mention any other details that might be useful.
ng serve works fine, its just ng build -prod
Here are the contents of my main.ts file: `import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { AppModule } from './app/app.module';
if (environment.production) { enableProdMode(); }
platformBrowserDynamic().bootstrapModule(AppModule); `
If there is more information needed, please let me know. I am trying to learn how to deploy my Angular website.
@MitchTalmadge I changed package.json to this, and finally resolved.The version server has 4.2.5,When i cleared the local directory Nodemoduls,The local installation of 4.2.5。Forced to change "^4.0.0" to "4.0.1"。 { "name": "xxxxx", "version": "1.0.1", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve --host 0.0.0.0 --port 8888", "build": "ng build --dev --aot", "clean": " ", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/common": "4.0.1", "@angular/compiler": "4.0.1", "@angular/core": "4.0.1", "@angular/forms": "4.0.1", "@angular/http": "4.0.1", "@angular/platform-browser": "4.0.1", "@angular/platform-browser-dynamic": "4.0.1", "@angular/router": "4.0.1", "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.24", "bootbox": "^4.4.0", "bootstrap": "4.0.0-alpha.6", "bootstrap-table": "1.11.2", "core-js": "^2.4.1", "jquery": "^3.2.1", "ng2-translate": "^5.0.0", "rxjs": "^5.1.0", "tether": "^1.4.0", "umebn-i18n": "^1.0.1", "zenap-smart-table": "^1.2.0", "zone.js": "^0.8.4" }, "devDependencies": { "@angular/cli": "1.2.0", "@angular/compiler-cli": "4.0.1", "@types/jasmine": "2.5.38", "@types/node": "~6.0.60", "codelyzer": "~2.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", "karma-chrome-launcher": "~2.0.0", "karma-cli": "~1.0.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "karma-coverage-istanbul-reporter": "^0.2.0", "protractor": "~5.1.0", "ts-node": "~2.0.0", "tslint": "~4.5.0", "typescript": "~2.2.0" } }
@sirius77cc Glad you got it worked out! :)
"prod": "ng build --env=prod --no-sourcemap" fixed for me
6 months and no official solution???
Yeah, none of these solutions have worked for me.
I FINALLY got it to work for me. Unbelievable it was because my entryModule path to the AppModule was incorrect. I fixed that and it works! Days of recreating my app from scratch, line by line, file by file, and it was a such as simple mistake but hard to notice.
If the compiler gave better error message, it would have saved me a LOTTTTT of time. Just saying "no appModule found at entryModule path, check that path is correct" would help.
@IAMtheIAM I can't find entryModule anywhere in my project. What file is this a part of?
I found out that another app of mine, which was using @angular/[email protected], @angular/*@4.2.4, and [email protected], successfully built using --prod, but when I ran npm update to get @angular/*@4.3.4 and [email protected], it produced the error. I tried several permutations of pinning various suggested versions of @angular/cli and enhanced-resolve along with several versions of @angular/* with no success. I really hope this is fixed soon.
Edit: However, pinning @angular/[email protected], @angular/*@4.2.4, and [email protected] to my other app did not fix the issue. So there is something else really obscure going on, possibly with another dependency that hasn't been mentioned? :/
It worked for me installing @angular/[email protected] with angular 4
"@angular/common": "^4.0.0", "@angular/compiler": "^4.0.0", "@angular/core": "^4.0.0", "@angular/forms": "^4.0.0", "@angular/http": "^4.0.0", "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0"
I have taken sample AngularCli app from Git. I installed all node modules via npm install. Now trying to build app via ng build -prod giving error, Environment:
- Angular2.
- Material Bootstrap.
- Angular-cli based project.
[ ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\ng test\prasad\src' @ ./src/main.ts 4:0-74 @ multi ./src/main.ts ]
Any help is really appreciated..... !!!!
The comand I tried may not be perfect: ng build --prod --aot=false
I resolved this issue in my project by pinning enhanced-resolve to 3.3.0. In case anyone needs to do it:
- npm shrinkwrap
- edit the shrinkwrap file and set all version of enhanced-resolve to 3.3.0
- npm install
More info here: https://stackoverflow.com/questions/15806152/how-do-i-override-nested-npm-dependency-versions
You can also do a similar thing with yarn. Just edit the yarn.lock file the same way, setting the resolved property for enhanced-resolve to "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz"
Good luck y'all.
sure will try it.
why this happening in build tools. isnt there any permanent solution irrespective of versions?
Try to use ng build --prod --aot=false, but build that appear in ./dist doesn't work. Files of bundles are not found. Does anyone catch this problem ?
Just change
"@angular/cli": "1.0.0"
from devDependencies to
"@angular/cli": "1.3.0"
run npm install and it should be fine.
In the current night I found perfect solution: remove everything, remove npm, remove node_modules. Burn them all! Dracarys! Then go to install npm, install angular-cli, have a good day
remove everything, remove npm, remove node_modules. Burn them all! Dracarys!
"nukeInstall": "rm -rf node_modules && npm cache clean --force && npm install"
@BOPOHOB On that note, I added this to my package.json scripts about a month ago. Works very well for that.
@jakeNiemiec @BOPOHOB I would also add to the removal of the npm-shrinkwrap.json and package-lock.json
"nukeInstall": "rm -rf node_modules npm-shrinkwrap.json package-lock.json && npm cache clean --force && npm install"
I followed the instruction from the README to upgrade angular-cli and now it works greathttps://github.com/angular/angular-cli#updating-angular-cli
below is the instruction:
To update Angular CLI to a new version, you must update both the global package and your project's local package.
Global package:
npm cache clean
npm install -g @angular/cli@latest```
Local project package:
```rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev @angular/cli@latest
npm install ```
@IRCraziestTaxi you can put entryModule on either your webpack config or your typescript config. Make sure the tsConfigPath points to the proper location of your tsconfig file. Also, the tsconfig settings are VERY picky, below I copied my entire working file so try that as is before modifying anything.
// webpack config
const ngToolsWebpack = require('@ngtools/webpack');
// webpack loader
{ test: /\.ts$/, loader: ['@ngtools/webpack'] },
// webpack plugin
new ngToolsWebpack.AotPlugin({
tsConfigPath: './tsconfig.ngtools-webpack.json',
entryModule: helpers.root('src/app-components/app/app.module') + '#AppModule', // here
debug: true
}),
// tsconfig.ngtools-webpack.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"noEmit": true,
"noEmitHelpers": true,
"paths": {
"@angular/*": [
"./node_modules/@angular/*"
]
},
"sourceMap": true,
"sourceRoot": ".",
"strictNullChecks": false,
"target": "es5",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"hammerjs",
"node"
]
},
"exclude": [
"./node_modules",
"./wwwroot",
"../backend-nodejs",
"./src/**/*.e2e.ts",
"./src/**/*.spec.ts"
],
"angularCompilerOptions": {
"genDir": "./compiled",
"entryModule": "src/app-components/app/app.module#AppModule", // or here
"skipMetadataEmit": true
},
"atom": {
"rewriteTsconfig": false
},
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"buildOnSave": false,
"compileOnSave": false
}