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 · 156 comments

Comments

@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 mentioned this issue Feb 9, 2017
@agarbutt
Copy link

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
Copy link

+1

@adessilly
Copy link

adessilly commented Feb 15, 2017

+1 (on Windows 10 64bits)

@IlyaSurmay
Copy link

+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
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
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
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
Copy link

jjaskulowski commented Feb 17, 2017 via email

@mayachirp
Copy link

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

@adessilly
Copy link

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
Copy link

See next. I found a solution for me.

I hope this helps.

@pbalaga
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 as completed Mar 5, 2017
@TheWalruzz
Copy link

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

@TheWalruzz
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
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
Copy link

pbalaga commented Mar 6, 2017

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

@hippee-lee
Copy link

@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
Copy link

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

@adessilly
Copy link

@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
Copy link

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
Copy link

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
Copy link

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

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

@darkguy2008
Copy link

Same here, in August. Any ideas?

@michalzubkowicz
Copy link

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
ng build was showing some error due to a bug in angular cli
Fixed by updating build script

angular/angular-cli#4551
@matinzd
Copy link

matinzd 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
Copy link

ssjoy76 commented Sep 25, 2018

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

@matinzd
Copy link

matinzd 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
Copy link

darkguy2008 commented Sep 25, 2018

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

@matinzd
Copy link

matinzd commented Sep 25, 2018

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

project is based on angular 4

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

ssjoy76 commented Sep 26, 2018 via email

@ssjoy76
Copy link

ssjoy76 commented Sep 26, 2018 via email

@affilnost
Copy link

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
Copy link

+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
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
Copy link

cyraid commented Feb 7, 2019

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

@omesquita
Copy link

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

For me it worked with this solution.

@ervivekmahajan
Copy link

/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ △ \ | '
\ / _ | | | | |/ _ | '
| | | | | | |
/ ___ | | | | (
| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@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
Copy link

@ervivekmahajan please read all the comments asap

@andrewantar
Copy link

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?

@AntJanus
Copy link

I still have this issue as well. I checked the various solutions but none worked for me.

@sachingeniushub
Copy link

s/@types/googlemaps/index.d.ts (1977,5): Duplicate identifier 'OK'.
u/node_modules/@types/googlemaps/index.d.ts (2124,33): Duplicate identifier 'DEFAULT'.
plz help

@Gajendrasinh
Copy link

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

Hello

i am using same version but not working. can help how to fixed this

Version:

@angular/cli: 1.0.0-rc.1
node: 8.11.4
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.10

Error
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Users\gazala\Desktop\GCDB_Workspace\GCDB6-Portal-Final\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

@Gajendrasinh
Copy link

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

This solution is not work.

This is my package version

Angular CLI: 1.7.4
Node: 8.11.4
OS: win32 x64
Angular: 2.4.10
... common, compiler, compiler-cli, core, forms, http
... platform-browser, platform-browser-dynamic

@angular/cli: 1.7.4
@angular/router: 3.4.10
@angular/tsc-wrapped: 0.5.2
@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.9.2
webpack: 3.11.0

@kannanwst
Copy link

image

angular 7 to 8 update face issue

@yy7054wyq5
Copy link

yy7054wyq5 commented Jul 25, 2019

  1. remove node_modules dir.
  2. execute 'npm cache clean --force'.
  3. delete package-lock.json.
    after these.
    aot is success!
    hope help u.

@tindalida
Copy link

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

worked for me too

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests