question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:129
  • Comments:156 (3 by maintainers)

github_iconTop GitHub Comments

251reactions
WiL-devcommented, Jun 13, 2017

Instead of use ng build --prod use ng 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

240reactions
pbalagacommented, Mar 5, 2017

Similar problem with 1.0.0-rc1 on Windows. Running ng build --prod gives

ERROR in Error encountered resolving symbol values statically. Could not resolve events relative to C:/Projects/craft-ng/editor/node_modules/blocking-proxy/built/lib/webdriver_commands.d.ts., resolving symbol WebDriverCommand in C:/Projects/craft-ng/editor/node_modules/blocking-proxy/built/lib/webdriver_commands.d.ts

ERROR in ./src/main.ts Module not found: Error: Can’t resolve ‘./$$_gendir/app/app.module.ngfactory’ in ‘C:\Projects\craft-ng\editor\src’ @ ./src/main.ts 4:0-74 @ multi ./src/main.ts

ng build --prod --aot=false executes without problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

27 - Stack Overflow
ERROR in ./src/main.server.ts Module not found: Error: Can't resolve './app/app.server.module.ngfactory'. When trying to pre-render using the command. ng ...
Read more >
Angular library: Module not found error | by Tanya Gray
This project is an Angular app and Angular library in one project. The app consumes the library directly, not via npm. The error...
Read more >
ng build --prod fails - Angular, Vue, React, Web ... - jQWidgets
I need to build using the AOT but i can't get it! ... src/app/app.module.ngfactory.js Module not found: Error: Can't resolve ...
Read more >
MDB Angular Pro - 4.3.1 does not build in the -prod mode
4 - Forth run of ng build -prod brings CLI error: ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in ...
Read more >
module not found: error: can't resolve '@angular/localize/init'
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...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found