Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thaniri opened this Issue Feb 9, 2017 · 148 comments

Comments

Projects
None yet
@thaniri
Copy link

thaniri commented Feb 9, 2017

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.

@Shijir Shijir referenced this issue Feb 9, 2017

Closed

$$_gendir issue #4555

@agarbutt

This comment has been minimized.

Copy link

agarbutt commented Feb 10, 2017

Having the same failure on both linux and windows platforms.

ERROR in Cannot read property 'map' of undefined

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/helix-app.module.ngfactory' in 'C:\Users\agarbutt\WebstormProjects\helix-ui\src'
 @ ./src/main.ts 3:0-85
 @ multi ./src/main.ts

main.ts

import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {enableProdMode} from "@angular/core";
import {environment} from "./environments/environment";
import {HelixAppModule} from "./app/";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic()
  .bootstrapModule(HelixAppModule)
  .catch(err => console.error(err));
@jjaskulowski

This comment has been minimized.

Copy link

jjaskulowski commented Feb 15, 2017

+1

@adessilly

This comment has been minimized.

Copy link

adessilly commented Feb 15, 2017

+1 (on Windows 10 64bits)

@IlyaSurmay

This comment has been minimized.

Copy link

IlyaSurmay commented Feb 16, 2017

+1
linux mint

ERROR in this._input.charCodeAt is not a function

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/vs/Work/GoFactTables/GoFactFrontend/src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

@mhamel06

This comment has been minimized.

Copy link
Contributor

mhamel06 commented Feb 16, 2017

This may or may not be helpful but I have noticed that the first error seems to be the primary cause and the Module not found error is generic and will happen any time something breaks the aot build.

In my case I was getting the following any time I had an empty scss file:

ERROR in Child compilation failed:
Module build failed: No input specified: provide a file name or a source string to process:
[object Object]

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/mhamel/Development/blispay/blispay-ui2/src'
 @ ./src/main.ts 4:0-76
 @ multi ./src/main.ts

As soon as I fixed the first error, the Module not found error resolved itself. From that, I would expect @IlyaSurmay and @agarbutt each have different project specific bugs. (Possibly aot compiler related)

Can you see if the --verbose flag gives you any more information about the error?

@thaniri

This comment has been minimized.

Copy link
Author

thaniri commented Feb 16, 2017

http://pastebin.com/Hmrs0Kh7

CTRL+F the document for 'was generated' to find out what command I used:
ng build -prod --verbose > aFile.txt
ng build -prod --verbose

If you want to try it yourself please clone this repo:
https://github.com/thaniri/angularPortfolio

I have no empty .scss files, and even if I attempt to add something to styles.css in the src folder, I get the same error.

@TheWalruzz

This comment has been minimized.

Copy link

TheWalruzz commented Feb 17, 2017

The same thing happens for me. No error other than:

ERROR in ./src/client.aot.ts Module not found: Error: Can't resolve './$$_gendir/browser.module.ngfactory' in '/home/pradej/Projekty/site-backoffice/src' @ ./src/client.aot.ts 2:0-75

I had to make a separate, plain client entry point for AOT, but it still doesn't work.

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { MainModule } from './browser.module';

enableProdMode();

platformBrowserDynamic().bootstrapModule(MainModule);

OS: Fedora 25 x64

Also, if that's helpful, my project is using Universal, but AOT is used for client only.

@jjaskulowski

This comment has been minimized.

Copy link

jjaskulowski commented Feb 17, 2017

@mayachirp

This comment has been minimized.

Copy link

mayachirp commented Feb 19, 2017

Same error when I upgraded to 4.0.0-beta.8. Previous version 4.0.0-beta.7 doesn't have this failure.

@adessilly

This comment has been minimized.

Copy link

adessilly commented Feb 19, 2017

This is how I fixed my issues with the last version of angular-cli :
https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.n4b11wso1

With the last version of angular-cli, ng build --prod seems to compile with --aot by default : I didn't know there was good practices to make project working with...

@nikoxgon

This comment has been minimized.

Copy link

nikoxgon commented Feb 23, 2017

See next. I found a solution for me.

I hope this helps.

@pbalaga

This comment has been minimized.

Copy link

pbalaga commented 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.

@thaniri thaniri closed this Mar 5, 2017

@TheWalruzz

This comment has been minimized.

Copy link

TheWalruzz commented Mar 6, 2017

This issue was closed, any advice for people still sufferring from this error?

@hydraslay hydraslay referenced this issue Mar 6, 2017

Closed

AoT support? #2

@TheWalruzz

This comment has been minimized.

Copy link

TheWalruzz commented Mar 6, 2017

Just to tell everyone: I eventually dropped @ngtools/webpack completely from my project and replaced it with @ultimate/aot-loader. AOT now finally works.

@WiL-dev

This comment has been minimized.

Copy link

WiL-dev commented Mar 6, 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

@pbalaga

This comment has been minimized.

Copy link

pbalaga commented Mar 6, 2017

@WiL-dev : I can confirm it works fine on 1.0.0-rc1. Thanks!

@hippee-lee

This comment has been minimized.

Copy link

hippee-lee commented Mar 6, 2017

@WiL-dev - I'm not sure ng build --env-prod builds with aot like ng build --prod does. If I run ng build --env=prod the tool generates the same size for my output as ng build --env=dev does. In addition running ng build --env=prod --aot=true gnerates the same error that I was origially getting. Unexpected value 'null' exported by the module 'MyModule' && down the stack Error: Can't resolve './$$_gendir/app/app.module.ngfactory'

This leads me to suspect that the cli tool is fine and it's my app that needs some updates before it can be --aot compiled.

Something I'll look into when I have a bit of time.

@russkayairina

This comment has been minimized.

Copy link

russkayairina commented Mar 7, 2017

unresolved, --env produces not the same output as --prod

@adessilly

This comment has been minimized.

Copy link

adessilly commented Mar 7, 2017

@russkayairina it's a normal behavior :
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).

To make your project working with aot, follow these steps :
https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.n4b11wso1

@dhilgarth

This comment has been minimized.

Copy link

dhilgarth commented Apr 11, 2017

This is still a problem. It happens even with the newly created project from ng new!

Full output:

d:\Temp\cli>ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 6.9.1
os: win32 x64

d:\Temp\cli>ng new cli-test
installing ng
  create .editorconfig
  create README.md
  create src\app\app.component.css
  create src\app\app.component.html
  create src\app\app.component.spec.ts
  create src\app\app.component.ts
  create src\app\app.module.ts
  create src\assets\.gitkeep
  create src\environments\environment.prod.ts
  create src\environments\environment.ts
  create src\favicon.ico
  create src\index.html
  create src\main.ts
  create src\polyfills.ts
  create src\styles.css
  create src\test.ts
  create src\tsconfig.app.json
  create src\tsconfig.spec.json
  create src\typings.d.ts
  create .angular-cli.json
  create e2e\app.e2e-spec.ts
  create e2e\app.po.ts
  create e2e\tsconfig.e2e.json
  create .gitignore
  create karma.conf.js
  create package.json
  create protractor.conf.js
  create tsconfig.json
  create tslint.json
Successfully initialized git.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Project 'cli-test' successfully created.

d:\Temp\cli>cd cli-test

d:\Temp\cli\cli-test>ng build --prod --env=prod
Hash: 0bfde11b73d9b21b101b
Time: 6189ms
chunk    {0} polyfills.7fd9b43f06a670d8299a.bundle.js (polyfills) 158 kB {3} [initial] [rendered]
chunk    {1}  (styles) 1.72 kB {3} [initial] [rendered]
chunk    {2} main.e1bb4892ef6fedc166cd.bundle.js (main) 806 kB [initial] [rendered]
chunk    {3} inline.65cd0835207a2ba3e811.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in E:/Temp/cli/cli-test/src/main.ts
Module not found: Error: Can't resolve './d:/Temp/cli/cli-test/src/$$_gendir/app/app.module.ngfactory' in 'E:\Temp\cli\cli-test\src'
 @ E:/Temp/cli/cli-test/src/main.ts 4:0-99
 @ multi ./src/main.ts

d:\Temp\cli\cli-test>
@LancerComet

This comment has been minimized.

Copy link

LancerComet commented Apr 14, 2017

I have fixed this issue in my project.

In my case, I have found two reasons:

1. I used jade template. You can't use jade with AOT.

// My component.

@Component({ 
  selector: 'app-some-component', 
  template: require('jade-loader!./some-component.jade')(),  // <--- This will break AOT bundling.
  styleUrls: ['./some-component.styl'] 
}) 
export class SomeCompoonent implements OnInit {
  // ...
}

How to fix: bring html back or turn off AOT.

2. Export an anonymous function by using export default will break AOT bundling.

// my-utils.ts

export default function () {  // <--- This will break AOT bundling too.
  // ...
}

How t fix: give it a name or turn off AOT.

// my-utils.ts

export deafult function myUtils () {  // Yeah! Everything is fine!
  //...
}
@warley996

This comment has been minimized.

Copy link

warley996 commented May 4, 2017

Very useful @WiL-dev your comment works fine for me. 4.0.0

@waratah

This comment has been minimized.

Copy link

waratah commented May 8, 2017

Building with --AOT today Angularcli V1.0.0

ERROR in Cannot assign to a reference or variable!

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts

Build without AOT and then running, no real help.
Breaking on the throw I find the component name

After investigation I found I was using variable name 'year' changing to taxYear resolved issue. Must be a clash with a method somewhere.

@danielvlasceanu

This comment has been minimized.

Copy link

danielvlasceanu commented Jan 15, 2018

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.

@mmamongy

This comment has been minimized.

Copy link

mmamongy commented Feb 18, 2018

that solution worked for me
willsoto/ng-chartist#94 (comment)

@Vinegar1225

This comment has been minimized.

Copy link

Vinegar1225 commented Mar 20, 2018

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.

@JivkoStoev

This comment has been minimized.

Copy link

JivkoStoev commented May 31, 2018

I've updated to
"@angular/cli": "^1.4.10",
"@angular/compiler-cli": "^4.2.6",
and problem was fixed.

@KhizerRehan

This comment has been minimized.

Copy link

KhizerRehan commented Jun 2, 2018

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!

screenshot_4

@ruipimentel

This comment has been minimized.

Copy link

ruipimentel commented Jun 28, 2018

@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.

@darkguy2008

This comment has been minimized.

Copy link

darkguy2008 commented Aug 9, 2018

Same here, in August. Any ideas?

@michalzubkowicz

This comment has been minimized.

Copy link

michalzubkowicz commented Aug 29, 2018

Check your tsconfig:
"angularCompilerOptions": {
"entryModule": "src/app/app.server.module#AppServerModule"
}

entryModule should have proper app module path

redtachyons pushed a commit to tachyons/product-service-frontend that referenced this issue Sep 7, 2018

Fix linux build
ng build was showing some error due to a bug in angular cli
Fixed by updating build script

angular/angular-cli#4551

@tachyons tachyons referenced this issue Sep 7, 2018

Merged

Fix linux build #1

@matinzd77

This comment has been minimized.

Copy link

matinzd77 commented Sep 15, 2018

_                      _                 ____ _     ___
 / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
/ ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
             |___/
@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.

`

@ssjoy76

This comment has been minimized.

Copy link

ssjoy76 commented Sep 25, 2018

This command is 100% work for solving this problem.
npm install enhanced-resolve@3.3.0

@matinzd77

This comment has been minimized.

Copy link

matinzd77 commented Sep 25, 2018

This command is 100% work for solving this problem.
npm install enhanced-resolve@3.3.0

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
@darkguy2008

This comment has been minimized.

Copy link

darkguy2008 commented Sep 25, 2018

Check this #11835 (comment) update to @angular/core 6.1.7

@matinzd77

This comment has been minimized.

Copy link

matinzd77 commented Sep 25, 2018

Check this #11835 (comment) update to @angular/core 6.1.7

project is based on angular 4

@darkguy2008

This comment has been minimized.

Copy link

darkguy2008 commented Sep 25, 2018

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.

@ssjoy76

This comment has been minimized.

Copy link

ssjoy76 commented Sep 26, 2018

@ssjoy76

This comment has been minimized.

Copy link

ssjoy76 commented Sep 26, 2018

@affilnost

This comment has been minimized.

Copy link

affilnost commented Sep 26, 2018

I had the the same problem. I fixed it by using ng-packagr v3.0.3 instead of v2.4.5 when building the npm-package.

@rameshpraja

This comment has been minimized.

Copy link

rameshpraja commented Oct 17, 2018

+1
linux mint

ERROR in this._input.charCodeAt is not a function

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/vs/Work/GoFactTables/GoFactFrontend/src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

I have the same issue which you are facing . have you find any solution if yes then please suggest me.

@jan1za

This comment has been minimized.

Copy link

jan1za commented Dec 28, 2018

I know this call is closed, but its the first link I found when googling, so here is my solution.

ERROR in ./src/main.server.ts
Module not found: Error: Can't resolve './app/app.server.module.ngfactory'

Using Angular 7.1.4, reason was I enabledIvy after upgrading from 6 to 7.

"angularCompilerOptions": {
  "enableIvy": true
} 

Removed the flag and all was good.

Ivy is still in Beta and should not be used in production see issue 21706

@cyraid

This comment has been minimized.

Copy link

cyraid commented Feb 7, 2019

For me it was having "rootDir" in my tsconfig.json ...
(I needed to remove it)

@omesquita

This comment has been minimized.

Copy link

omesquita commented Feb 13, 2019

This command is 100% work for solving this problem.
npm install enhanced-resolve@3.3.0

For me it worked with this solution.

@ervivekmahajan

This comment has been minimized.

Copy link

ervivekmahajan commented Feb 14, 2019

/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | '
\ / _ | | | | |/ _ | '
| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || |___ | |
/
/ __| |
|_
, |_,||_,|| _||_|
|___/
@angular/cli: 1.0.1
node: 6.14.3
os: linux x64
@angular/common: 4.3.5
@angular/compiler: 4.3.5
@angular/core: 4.3.5
@angular/forms: 4.3.5
@angular/http: 4.3.5
@angular/platform-browser: 4.3.5
@angular/platform-browser-dynamic: 4.3.5
@angular/router: 4.3.5
@angular/cli: 1.0.1
@angular/compiler-cli: 4.3.5

and this is the error

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/var/www/html/v2site/lite_frontend/src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

please suggest solution asap

@darkguy2008

This comment has been minimized.

Copy link

darkguy2008 commented Feb 14, 2019

@ervivekmahajan please read all the comments asap

@andrewantar

This comment has been minimized.

Copy link

andrewantar commented Mar 18, 2019

Still having this issue. All the proposed solutions don't work: no absolute paths, rootDir doesnt exist, aot=false doesn't work since buildOptimizer requires AOT. Using Angular 7.2. Any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.