ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
See original GitHub issueOS?
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.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:129
- Comments:156 (3 by maintainers)
Instead of use
ng build --prod
useng build --env=prod
UPDATE
As many of us (thx) have mention, this doesn’t build with aot so, it’s the same that the plain ng build at the end (as says @adessilly ng build --env=prod : replace environment.ts by environment.prod.ts, but it’s a simple ng build. ng build --prod : improved build with aot + environment.prod.ts replacement (before, it was ng build --prod --aot) )
The most easy workaround (at least for me), was to create a new whole project with the last Angular CLI version, and moves the src folder. It’s no straight forward, so please read the migration guide and don’t forget to make a backup before.
Migration guide
Similar problem with 1.0.0-rc1 on Windows. Running
ng build --prod
givesng build --prod --aot=false
executes without problems.