"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)
thanks @deerawan it'swork for me. It was typescript issue...
Still have this problem, I have tried everything listed here.
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
Same problem here...Latest version 1.6.5...nothing works from this post
@juanlet check this out https://stackoverflow.com/questions/39685179/angular-2-no-ngmodule-metadata-found maybe this trick can help you
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.
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.
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.
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 :).
@daniloagostinho thanks a lot ... It worked and ng serve is working..
@evolkmann thanks... it worked!!!
Had the same probelm and, unfortunately, nothing from this post helped me.
Solved the error by removing "skipTemplateCodegen": true line from tsconfig.json file.
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
- npm remove webpack
- npm install [email protected]
For me, removing the include section from tsconfig.json did the trick. go figure :-)
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
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"
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
Agreed getting the same error from update 5 to 6.
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.
@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.