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

After upgrading to Angular 6, I encountered the "ERROR in No NgModule metadata found for 'AppModule'." with the angular-bootstrap-md package, which requires a tsconfig.json "include" as follows:

"include": ["node_modules/angular-bootstrap-md/**/*.ts", "src/**/*.ts"],

After days of troubleshooting and hair pulling, the solution was to arrange the list so that the app.module.ts was located first, under "src/**/*.ts". An Angular bug, perhaps?

"include": ["src/**/*.ts","node_modules/angular-bootstrap-md/**/*.ts" ],

I genuinely hope this helps somebody, as I tried everything in this posting and nothing helped. After this change, everything compiles and works beautifully, as expected.

bahrigungor avatar May 11 '18 04:05 bahrigungor

@bahrigungor this solved my issue as well. The include shouldn't matter, but apparently it does... Thank you for randomly trying this and posting.

shortcircuit21 avatar May 11 '18 19:05 shortcircuit21

@bahrigungor solution helped solved the issue. I've updated src/tsconfig.app.json so that app.module.ts is mentioned explicitly in the "files" property besides the "**/*" from the "include" property: { "files": [ "app/app.module.ts" ], "include": [ "**/*" ] }

I also created a new application with the 6.0.1 CLI. The tsconfig.json and tsconfig.app.json don't have these properties mentioned but it builds just as well.

aipirvu avatar May 12 '18 14:05 aipirvu

@bahrigungor this solved the issue, thank you very much

Detys avatar May 15 '18 09:05 Detys

@bahrigungor solved my issue as well after 4 hours of yanking hair out of my skull! THANK YOU!!!!!

srenbo avatar May 15 '18 23:05 srenbo

ERROR in multi ./src/styles.css ../node_modules/jqwidgets-scripts/jqwidgets/styles/jqx.base.css Module not found: Error: Can't resolve 'C:\projetos\node_modules\jqwidgets-scripts\jqwidgets\styles\jqx.base.css' in 'C:\projetos\jqwidgets-angular-cli-app' ERROR in No NgModule metadata found for 'AppModule'.

developercwb avatar May 18 '18 16:05 developercwb

Leaving this comment so others don't feel lonely... none of the many brilliant ideas on here have helped me get over this issue. I only get this issue when I run ng serve -aot true. Not sure how to get past it. My app runs, but when I run in AOT mode, I get this error.

aaronfrost avatar May 19 '18 01:05 aaronfrost

After much of hair pulling, finally got it working for Angular 6 by adding following in the tsconfig.json

"files": [ "src/app/app.module.ts" ]

nawnitraman avatar May 20 '18 13:05 nawnitraman

@nawnitraman That worked for me!!

Do you know why it works?

vchtelmakh avatar Jun 12 '18 19:06 vchtelmakh

This works because it forces the app module to be among the first files to be loaded. Other logic depends on it being loaded first. When this does not happen thing break. The real question i think is: what changed that now it requires this to be mentioned explicitly in the files property? I asume that the module was loaded first by default previous to this version.

aipirvu avatar Jun 12 '18 20:06 aipirvu

I ran into this issue recently myself. I have a minimal repro that does not list angular-cli as a dependency, only ngtools/webpack and webpack itself.

Because this issue has had quite a few different problems conflated and the original issue was closed, I opened a new one: #11218

however if the discussion should happen here I am happy to do that instead

wiltzius avatar Jun 13 '18 03:06 wiltzius

Hi I find a solution: Edit the angular.json file and invert order of your-project and your-project-e2e Now: ng g c componentName work correctly

Actisoft1 avatar Jul 05 '18 14:07 Actisoft1

Update your tsconfig.app.json file with:

"files": [
    "app/app.module.ts"
  ],

It works fine to me.

luixaviles avatar Aug 15 '18 19:08 luixaviles

For me, in order to make it compile, i had to add this to tsconfig.app.json:

"files": [
    "./app/app.module.ts",
    "./main.ts",
    "./polyfills.ts"
  ],
  "include": [
    "./**/*.ts"
  ]

kzawada93 avatar Aug 22 '18 07:08 kzawada93

I got past this problem by not declaring platformBrowserDynamic as mentioned here: https://stackoverflow.com/questions/39685179/angular-2-no-ngmodule-metadata-found

which to me, totally makes zero sense 😬 👍

michahell avatar Aug 30 '18 15:08 michahell

Thanks @175451 Faced same issue. Resolved after adding below to tsconfig.app.json "files": [ "./app/app.module.ts", "./main.ts", "./polyfills.ts" ],

vimalans avatar Nov 27 '18 00:11 vimalans

I have got same error but for another module down the route. Error occurs on building secondary app (generated via angular CLI command: ng generate application myApp) and I have used in this application barrel import somewhere in its structure. By replacing import with direct/deeper one I have removed the issue.

luckylooke avatar Dec 11 '18 13:12 luckylooke

I am getting this "ERROR in No NgModule metadata found for 'AppModule'." please help me

nagipogu avatar Feb 04 '19 06:02 nagipogu

@nagipogu did you manage to figure it out?

suparnavg avatar Feb 12 '19 06:02 suparnavg

I faced this issue right now and i fixed it. The Problem was that i had a different name spelling in the exported class varName in the module page file. The app-routing.module is referencing at this exact name in the module what is inserted there. If this both are different, you ll get the error Message : "ERROR in No NgModule metadata found for 'AppModule'.

My Setup: Ionic:

Ionic CLI : 5.2.2 Ionic Framework : @ionic/angular 4.6.0 @angular-devkit/build-angular : 0.13.9 @angular-devkit/schematics : 7.3.9 @angular/cli : 7.3.9 @ionic/angular-toolkit : 1.5.1

ck88ger avatar Jul 13 '19 09:07 ck88ger