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

"No NgModule metadata found for 'AppModule'" after Upgrade to Angular 5.1.0 and AngularCli 1.6.0

Open evolkmann opened this issue 8 years ago • 81 comments

Versions

Angular CLI: 1.6.0
Node: 8.9.1
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.0.0
@angular/cli: 1.6.0
@angular/flex-layout: 2.0.0-beta.10-4905443
@angular/material: 5.0.0
@ngtools/json-schema: 1.1.0
@schematics/schematics: 0.0.10
typescript: 2.5.0
webpack: 3.10.0

Repro steps

  • Upgrade @angular from 5.0.2 to 5.1.0
  • Upgrade @angular/cli from 1.5.2 to 1.6.0
  • Run ng serve

Observed behavior

After doing the upgrade, the following error arises. I was able to resolve the issue as described here.

ERROR in Error: No NgModule metadata found for 'AppModule'.
    at NgModuleResolver.resolve (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler\bundles\compiler.umd.js:20249:23)
    at CompileMetadataResolver.getNgModuleMetadata (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler\bundles\compiler.umd.js:15218:60)
    at visitLazyRoute (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler\bundles\compiler.umd.js:31063:104)
    at AotCompiler.listLazyRoutes (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler\bundles\compiler.umd.js:31031:20)
    at AngularCompilerProgram.listLazyRoutes (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler-cli\src\transformers\program.js:156:30)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\compiler-cli\src\ngtools_api.js:44:36)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\angular_compiler_plug
in.js:247:66)
    at Promise.resolve.then.then (C:\Users\volkende\WebstormProjects\project-name\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:561:50)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Desired behavior

  • Since no real changes have been made in app.module.ts, as a developer I don't want to have to take this step

Mention any other details that might be useful (optional)

  • Before this issue occured, I had to explicitly npm i --save-dev webpack to be able to run ng serve at all (#7334)

evolkmann avatar Dec 08 '17 08:12 evolkmann

thanks @deerawan it'swork for me. It was typescript issue...

santosh-more avatar Feb 06 '18 18:02 santosh-more

Still have this problem, I have tried everything listed here.

ghost avatar Feb 13 '18 17:02 ghost

Same here the NgModule metadata error. Fixed it fixing typescript version to 2.6.2

Angular CLI: 1.7.1 Node: 6.9.1 OS: darwin x64 Angular: 5.2.6 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

@angular/cli: 1.7.1 @angular-devkit/build-optimizer: 0.3.2 @angular-devkit/core: 0.3.2 @ngtools/json-schema: 1.2.0 typescript: 2.6.2 webpack: 3.11.0

GasparErrobidart avatar Feb 26 '18 16:02 GasparErrobidart

Same problem here...Latest version 1.6.5...nothing works from this post

juanlet avatar Feb 28 '18 04:02 juanlet

@juanlet check this out https://stackoverflow.com/questions/39685179/angular-2-no-ngmodule-metadata-found maybe this trick can help you

alyssa19 avatar Feb 28 '18 10:02 alyssa19

I had an extra .catch() statement in main.ts I had to remove. First starting ng serve, then adding spaces inside main.ts seemed to solve the issue for me the second time it happened.

rovercoder avatar Mar 02 '18 09:03 rovercoder

I had to remove my existing typescript version 2.5.3 and install [email protected] after hours of trying to figure it out . And its working fine now.

Panther59 avatar Mar 07 '18 08:03 Panther59

Having the same problem with using regular angular-cli on a newly purchased macbook pro. I get the error message the first time I run ng serve, but as soon as I make any change, the error goes away, and the application works.

I have tried deleting node_modules and reinstalling my dependencies using yarn add, and I upgraded typescript to 2.6.2, but the issue persists.

Edit: Solved the issue, I am lazily loading my paths, and I had defined two paths:

{ path: 'login', loadChildren: 'app/login/login.module#LoginModule' }, { path: 'signup', loadChildren: 'app/signup/signup.module#LoginModule' }

As you can see, I was trying to import LoginModule on both places. Changed to the correct import, and it works.

TLDR: Don't copy paste your own code.

kristine-sl avatar Mar 08 '18 10:03 kristine-sl

As many times before, removing the package-lock.json-file, before removing node_modules and reinstalling, solved the problem. It seems to me that the package-lock.json-file does more harm than good :).

rujorgensen avatar Mar 08 '18 10:03 rujorgensen

@daniloagostinho thanks a lot ... It worked and ng serve is working..

abhinavJai avatar Mar 12 '18 07:03 abhinavJai

@evolkmann thanks... it worked!!!

vseeberger avatar Apr 11 '18 18:04 vseeberger

Had the same probelm and, unfortunately, nothing from this post helped me. Solved the error by removing "skipTemplateCodegen": true line from tsconfig.json file.

oleh-shalyhin avatar Apr 17 '18 15:04 oleh-shalyhin

I finally resolved this issue. Resolution below. :-)

Update the Angular CLI version to latest – as of today it’s 1.7.4

  • How to check the version of @angular/cli
    • ng --version Go to the folder and type the following commands to update CLI.
    • npm remove @angular/cli
    • npm install —save-dev @angular/cli@latest Make sure that the Webpack version is 3.11.0
  • How to check the version of Webpack
    • npm list webpack
  • How to update webpack

csrssrinivas avatar Apr 23 '18 07:04 csrssrinivas

For me, removing the include section from tsconfig.json did the trick. go figure :-)

urish avatar Apr 25 '18 03:04 urish

I'm getting this error in freshly generated project. ng --version output:

Angular CLI: 1.7.4
Node: 8.3.0
OS: win32 x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@ngtools/json-schema: 1.2.0
typescript: 2.5.3
webpack: 3.11.0

UPD Just updated NodeJS to 10.0.0. Still getting this error

Mesya82 avatar Apr 25 '18 23:04 Mesya82

Same issue with Angular 6:

"@angular/cli": "6.0.0-rc.7",
"@angular/animations": "6.0.0-rc.5",
"@angular/cdk": "6.0.0-rc.5",
"@angular/common": "6.0.0-rc.5",
"@angular/compiler": "6.0.0-rc.5",
"@angular/core": "6.0.0-rc.5",
"@angular/flex-layout": "6.0.0-beta.15",
"@angular/forms": "6.0.0-rc.5",
"@angular/http": "6.0.0-rc.5",
"@angular/material": "6.0.0-rc.5",
"@angular/platform-browser": "6.0.0-rc.5",
"@angular/platform-browser-dynamic": "6.0.0-rc.5",
"@angular/router": "6.0.0-rc.5",
"typescript": "2.7.2"

SerkanSipahi avatar May 02 '18 07:05 SerkanSipahi

Same error with latest versions:

Angular CLI: 6.0.0
Node: 9.4.0
OS: win32 x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@angular/cdk                      6.0.1
@angular/material                 6.0.1
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

wiedikerli avatar May 08 '18 09:05 wiedikerli

Agreed getting the same error from update 5 to 6.

shortcircuit21 avatar May 09 '18 21:05 shortcircuit21

For anyone using Angular 6:

The only thing that has worked for me is removing the "files" or "include" property from my tsconfig.json and adding those file paths to the "include" property in my tsconfig.app.json.

ghost avatar May 10 '18 19:05 ghost

@iamtristangordon TypeScript's tsconfig extends functionality only applies to the compilerOptions field. All others are ignored. So yes, any of those other fields (files, includes, etc.) need to be in the directly referenced tsconfig.

clydin avatar May 10 '18 19:05 clydin