angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open thaniri opened this issue 9 years ago • 156 comments

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.

thaniri avatar Feb 09 '17 05:02 thaniri

I just ran into the same issue. Since we switched to aot build for development, this issue was troubling. And in my case it was caused by a previous fix involving angularCompilerOptions in the tsconfig.app.json:

I basically had

before - not working

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "target": "es5",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "angularCompilerOptions": {
    "annotateForClosureCompiler": false,
    "skipMetadataEmit" : true,
    "skipTemplateCodegen": true
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

removing the angularCompilerOptions solved the issue:

working

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "target": "es5",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

With this config, we can use the ng serve with aot: "start": "ng serve --aot --proxy-config proxy.conf.json"

IsNull avatar Nov 30 '17 09:11 IsNull

If anybody was able to get here... In my case it was some error in CSS file connected with one of components. Just removed bug and it works.

Lazarencjusz avatar Dec 08 '17 22:12 Lazarencjusz

update npm install [email protected] for me it's working fine

nandhuems avatar Dec 12 '17 13:12 nandhuems

This was a frustrating one... Especially since I had this issue months ago, solved it and then totally forgot the fix and then saw it pop up again in another project.

In my case neither upgrading the CLI or installing enhanced resolve 3.3.0 fixed the issue.

For me it was simply a casing issue. All of our apps are kept under an 'Apps' folder, but in both my Webpack entry and ngtools aot entryModule, I had the folder in lowercase as 'apps'.

Hopefully that helps someone else and also future me :)

10derloin avatar Dec 13 '17 02:12 10derloin

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.

danielvlasceanu avatar Jan 15 '18 10:01 danielvlasceanu

that solution worked for me https://github.com/willsoto/ng-chartist/issues/94#issuecomment-292346092

mmamongy avatar Feb 18 '18 19:02 mmamongy

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.

Vinegar1225 avatar Mar 20 '18 15:03 Vinegar1225

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

JivkoStoev avatar May 31 '18 12:05 JivkoStoev

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

KhizerRehan avatar Jun 02 '18 09:06 KhizerRehan

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

ruipimentel avatar Jun 28 '18 22:06 ruipimentel

Same here, in August. Any ideas?

darkguy2008 avatar Aug 09 '18 22:08 darkguy2008

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

entryModule should have proper app module path

michalzubkowicz avatar Aug 29 '18 11:08 michalzubkowicz

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

`

matinzd avatar Sep 15 '18 08:09 matinzd

This command is 100% work for solving this problem. npm install [email protected]

ssjoy76 avatar Sep 25 '18 19:09 ssjoy76

This command is 100% work for solving this problem. npm install [email protected]

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

matinzd avatar Sep 25 '18 19:09 matinzd

Check this https://github.com/angular/angular-cli/issues/11835#issuecomment-419097658 update to @angular/core 6.1.7

darkguy2008 avatar Sep 25 '18 20:09 darkguy2008

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

project is based on angular 4

matinzd avatar Sep 25 '18 20:09 matinzd

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.

darkguy2008 avatar Sep 25 '18 21:09 darkguy2008

May be your angular version is grater than 4.0.0 because of don't work properly this command. please check your version.

On Wed, Sep 26, 2018 at 3:13 AM DARKGuy (Alemar) [email protected] wrote:

Check this #11835 (comment) https://github.com/angular/angular-cli/issues/11835#issuecomment-419097658 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 rxjs-compat. I just finished migrating an old project running in production made in v4 to v6 in less than a week.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/4551#issuecomment-424503263, or mute the thread https://github.com/notifications/unsubscribe-auth/AoS6xHrNo0XmHbIlkPobxqgLdhM9EXRTks5uepx0gaJpZM4L7u-Y .

ssjoy76 avatar Sep 26 '18 04:09 ssjoy76

May be your angular version is grater than 4.0.0 because of don't work properly this command. please check your version.

On Wed, Sep 26, 2018 at 2:00 AM matinzd77 [email protected] wrote:

This command is 100% work for solving this problem. npm install [email protected]

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/4551#issuecomment-424480699, or mute the thread https://github.com/notifications/unsubscribe-auth/AoS6xG2E1cUiC2CFJbyXUoZ4DQvVKElfks5ueotSgaJpZM4L7u-Y .

ssjoy76 avatar Sep 26 '18 04:09 ssjoy76