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.
I just ran into the same issue. Since we switched to aot build for development, this issue was troubling. And in my case it was caused by a previous fix involving angularCompilerOptions in the tsconfig.app.json:
I basically had
before - not working
{
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"lib": [
"es2016",
"dom"
],
"outDir": "../out-tsc/app",
"target": "es5",
"module": "es2015",
"baseUrl": "",
"types": []
},
"angularCompilerOptions": {
"annotateForClosureCompiler": false,
"skipMetadataEmit" : true,
"skipTemplateCodegen": true
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
removing the angularCompilerOptions solved the issue:
working
{
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"lib": [
"es2016",
"dom"
],
"outDir": "../out-tsc/app",
"target": "es5",
"module": "es2015",
"baseUrl": "",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
With this config, we can use the ng serve with aot:
"start": "ng serve --aot --proxy-config proxy.conf.json"
If anybody was able to get here... In my case it was some error in CSS file connected with one of components. Just removed bug and it works.
update npm install [email protected] for me it's working fine
This was a frustrating one... Especially since I had this issue months ago, solved it and then totally forgot the fix and then saw it pop up again in another project.
In my case neither upgrading the CLI or installing enhanced resolve 3.3.0 fixed the issue.
For me it was simply a casing issue. All of our apps are kept under an 'Apps' folder, but in both my Webpack entry and ngtools aot entryModule, I had the folder in lowercase as 'apps'.
Hopefully that helps someone else and also future me :)
I am working on an app based on the ASP.NET Core Angular template, which does not come with AngularCLI. I had this error only on publishing the solution, without no other information. Turns out I moved the app.browser.module.ts and app.server.module.ts files from the app folder to app/modules and I forgot to update the new entryModule paths (thanks @tenderloin420 ) in the AngularCompilerPlugin/AotPlugin sections in webpack.config.js. The publishing worked once I corrected the paths.
that solution worked for me https://github.com/willsoto/ng-chartist/issues/94#issuecomment-292346092
Still facing the same error, update the "enhanced-resolve" seems work, and the "ng build --env=prod --output-hashing" will build different outputs, which is much bigger than the "ng build --prod" output, that is not our expect.
I've updated to "@angular/cli": "^1.4.10", "@angular/compiler-cli": "^4.2.6", and problem was fixed.
Currently using:
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | ' \ / _ | | | | |/ _ | '| | | | | | |
/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
Angular CLI: 1.7.4 Node: 8.9.0 OS: win32 x64 Angular: 5.1.0 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router
@angular/cdk: 5.2.5 @angular/cli: 1.7.4 @angular/material: 5.2.5 @angular-devkit/build-optimizer: 0.3.2 @angular-devkit/core: 0.3.2 @angular-devkit/schematics: 0.3.2 @ngtools/json-schema: 1.2.0 @ngtools/webpack: 1.10.2 @schematics/angular: 0.3.2 @schematics/package-update: 0.3.2 typescript: 2.5.3 webpack: 3.11.0
BUT while doing AOT build it is giving me following error help required! Thanks!

@KhizerRehan same CLI v1.7.4 here, the only major difference being the operating system (Fedora 28).
If I'm not mistaken, this is the latest v1.* series launched to this day, but the bug persists.
Same here, in August. Any ideas?
Check your tsconfig: "angularCompilerOptions": { "entryModule": "src/app/app.server.module#AppServerModule" }
entryModule should have proper app module path
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
@angular/cli: 1.2.6
node: 8.11.1
os: win32 x64
@angular/animations: 4.4.7
@angular/common: 4.4.7
@angular/compiler: 4.4.7
@angular/core: 4.4.7
@angular/forms: 4.4.7
@angular/http: 4.4.7
@angular/platform-browser: 4.4.7
@angular/platform-browser-dynamic: 4.4.7
@angular/router: 4.4.7
@angular/cli: 1.2.6
@angular/compiler-cli: 4.4.7
@angular/language-service: 4.4.7
I executed this command ng build --prod and the error was:
ERROR in Metadata version mismatch for module F:/***/node_modules/@ng-select/ng-select/ng-select.d.ts, found version 4, expected 3, resolving symbol AppModule in F:/***/src/app/app.module.ts, resolving symbol AppModule in F:/***/src/app/app.module.ts
(node:17688) DeprecationWarning: Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead.
`
This command is 100% work for solving this problem. npm install [email protected]
This command is 100% work for solving this problem. npm install [email protected]
Still problem is going on ...
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/user/Server/v2/Battery-Server-Panel/src'
@ ./src/main.ts 3:0-74
@ multi ./src/main.ts
Check this https://github.com/angular/angular-cli/issues/11835#issuecomment-419097658 update to @angular/core 6.1.7
Check this #11835 (comment) update to @angular/core 6.1.7
project is based on angular 4
Then upgrade? 4 vs 6 isn't that hard aside from a few breaking changes with rxjs that can be fixed with just installing rxjs-compat. I just finished migrating an old project running in production made in v4 to v6 in less than a week. I know it's not the solution, but the fix is working in v6.
May be your angular version is grater than 4.0.0 because of don't work properly this command. please check your version.
On Wed, Sep 26, 2018 at 3:13 AM DARKGuy (Alemar) [email protected] wrote:
Check this #11835 (comment) https://github.com/angular/angular-cli/issues/11835#issuecomment-419097658 update to @angular/core 6.1.7
project is based on angular 4
Then upgrade? 4 vs 6 isn't that hard aside from a few breaking changes with rxjs that can be fixed with rxjs-compat. I just finished migrating an old project running in production made in v4 to v6 in less than a week.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/4551#issuecomment-424503263, or mute the thread https://github.com/notifications/unsubscribe-auth/AoS6xHrNo0XmHbIlkPobxqgLdhM9EXRTks5uepx0gaJpZM4L7u-Y .
May be your angular version is grater than 4.0.0 because of don't work properly this command. please check your version.
On Wed, Sep 26, 2018 at 2:00 AM matinzd77 [email protected] wrote:
This command is 100% work for solving this problem. npm install [email protected]
Still problem is going on ...
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/user/Server/v2/Battery-Server-Panel/src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/4551#issuecomment-424480699, or mute the thread https://github.com/notifications/unsubscribe-auth/AoS6xG2E1cUiC2CFJbyXUoZ4DQvVKElfks5ueotSgaJpZM4L7u-Y .