"No NgModule metadata found for 'AppModule'" after Upgrade to Angular 5.1.0 and AngularCli 1.6.0
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
@angularfrom5.0.2to5.1.0 - Upgrade
@angular/clifrom1.5.2to1.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 webpackto be able to runng serveat all (#7334)
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 this solved my issue as well. The include shouldn't matter, but apparently it does... Thank you for randomly trying this and posting.
@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.
@bahrigungor this solved the issue, thank you very much
@bahrigungor solved my issue as well after 4 hours of yanking hair out of my skull! THANK YOU!!!!!
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'.
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.
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 That worked for me!!
Do you know why it works?
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.
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
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
Update your tsconfig.app.json file with:
"files": [
"app/app.module.ts"
],
It works fine to me.
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"
]
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 😬 👍
Thanks @175451
Faced same issue. Resolved after adding below to tsconfig.app.json
"files": [
"./app/app.module.ts",
"./main.ts",
"./polyfills.ts"
],
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.
I am getting this "ERROR in No NgModule metadata found for 'AppModule'." please help me
@nagipogu did you manage to figure it out?
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