Skip to content

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

Closed

Description

@thaniri

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.

Activity

  1. agarbutt commented on Feb 10, 2017

    @agarbutt

    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));
  2. jjaskulowski commented on Feb 15, 2017

    @jjaskulowski

    +1

  3. adessilly commented on Feb 15, 2017

    @adessilly

    +1 (on Windows 10 64bits)

  4. IlyaSurmay commented on Feb 16, 2017

    @IlyaSurmay

    +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
    
    
  5. mhamel06 commented on Feb 16, 2017

    @mhamel06
    Contributor

    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?

  6. thaniri commented on Feb 16, 2017

    @thaniri
    Author

    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.

  7. TheWalruzz commented on Feb 17, 2017

    @TheWalruzz

    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.

  8. jjaskulowski commented on Feb 17, 2017

    @jjaskulowski
  9. mayachirp commented on Feb 19, 2017

    @mayachirp

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

  10. adessilly commented on Feb 19, 2017

    @adessilly

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

  11. Gonic0 commented on Feb 23, 2017

    @Gonic0

    See next. I found a solution for me.

    I hope this helps.

  12. pbalaga commented on Mar 5, 2017

    @pbalaga

    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.

  13. TheWalruzz commented on Mar 6, 2017

    @TheWalruzz

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

  14. TheWalruzz commented on Mar 6, 2017

    @TheWalruzz

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

  15. 148 remaining items

  16. jan1za commented on Dec 28, 2018

    @jan1za

    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

  17. cyraid commented on Feb 7, 2019

    @cyraid

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

  18. omesquita commented on Feb 13, 2019

    @omesquita

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

    For me it worked with this solution.

  19. ervivekmahajan commented on Feb 14, 2019

    @ervivekmahajan

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

  20. darkguy2008 commented on Feb 14, 2019

    @darkguy2008

    @ervivekmahajan please read all the comments asap

  21. andrewantar commented on Mar 18, 2019

    @andrewantar

    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?

  22. AntJanus commented on Apr 18, 2019

    @AntJanus

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

  23. sachingeniushub commented on May 10, 2019

    @sachingeniushub

    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

  24. Gajendrasinh commented on May 13, 2019

    @Gajendrasinh

    @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

  25. Gajendrasinh commented on May 16, 2019

    @Gajendrasinh

    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

  26. kannanwst commented on Jun 11, 2019

    @kannanwst

    image

    angular 7 to 8 update face issue

  27. yy7054wyq5 commented on Jul 25, 2019

    @yy7054wyq5
    1. remove node_modules dir.
    2. execute 'npm cache clean --force'.
    3. delete package-lock.json.
      after these.
      aot is success!
      hope help u.
  28. tindalida commented on Jul 29, 2019

    @tindalida

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

    worked for me too

  29. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  30. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions