"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)
I got the same error. The issue is fixed only when i manually re installed angular/cli. The webpack should come as a part of @angular/cli.
npm remove webpack
npm install --save-dev @angular/cli@latest.
This should fix your issue. If this didn't, clear the whole node_modules folder then
npm cache clean --force
npm install
npm install --save-dev @angular/cli@latest
If @angular/cli install fails
Retry npm install --save-dev @angular/cli@latest again.
I had this same error when upgrading. I simply deleted the node_modules folder and ran npm install again, all worked fine.
I just ran into this issue but with the cli on 1.5.5 and angular on 5.1.0
I just ran into this issue, as well. I just upgraded from Angular v4 to v5.1.0 and @ ngtools/webpack v1.9.0. I removed my node_modules directory and cleared npm cache, but I'm still getting the missing metadata error post-compilation.
Thanks for your feedback so far. I will now investigate again and can then respond properly to your suggestions. But for sure I deleted node_modules a few times in the process (@mattytommo ).
Will give feedback soon..
So I reverted what I did earlier today (actually a little git accident, but that's another story) and updated again. Now I documented every step and took into account the previous answers.
npm i -g @angular/cli@latestrm -rf node_modules/rd /s /q node_modules- Update project dependencies as follows (manually in
package.json):
"@angular/animations": "5.0.2" -> "5.1.0",
"@angular/cdk": "5.0.0-rc0" -> "5.0.0",
"@angular/common": "5.0.2" -> "5.1.0",
"@angular/compiler": "5.0.2" -> "5.1.0",
"@angular/core": "5.0.2" -> "5.1.0",
"@angular/forms": "5.0.2" -> "5.1.0",
"@angular/http": "5.0.2" -> "5.1.0",
"@angular/material": "5.0.0-rc0" -> "5.0.0",
"@angular/platform-browser": "5.0.2" -> "5.1.0",
"@angular/platform-browser-dynamic": "5.0.2" -> "5.1.0",
"@angular/router": "5.0.2" -> "5.1.0"
npm cache clear --forcenpm cache verifynpm install- The #7334 Error:
Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Enzo\WebstormProjects\project-name.de\node_modules\html-webpack-plugin\lib\compiler.js:11:26)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Enzo\WebstormProjects\project-name.de\node_modules\html-webpack-plugin\index.js:7:21)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
npm uninstall webpacknpm install --save-dev --save-exact @angular/cli@latest(from @JinsPeter 's answer)
After all that ng serve and ng build [--prod] work fine.
New findings:
- The new described steps are working just fine and may be a workaround
- What I originally wrote under Observed Behaviour is no longer needed
What I do not understand:
- What do steps 8 and 9 do different versus steps 2, 4 and 6?
- Both should remove the dependencies (or at least
webpack) and perform a clean reinstall
Hope that information helps
In the meantime we also had a build in our CI-Environment. Before pushing, I cleaned the cache and after that, the build was successful without all the complicated stuff above. A simple npm install and ng build --prod worked perfectly fine.
You can close the issue now as it was build mistake ryt?
We're not using angular-cli directly. We use webpack to do the compilation. We're still getting the error after doing a compile.
I'm also experiencing this issue after updating from angular 4.4.6 to 5.1.0 and angular-cli 1.4.5 to 1.6.0. I've tried all the suggested fixes and am still getting the same error: "No NgModule metadata found for 'AppModule'." JIT builds work fine for me. When doing an AOT build it seems like it just doesn't include a bunch of the TypeScript files in the output. My main.bundle.js and vendor.bundle.js files are significantly smaller than their JIT counterparts.
I had this error message when running ng serve or ng build, but found that it was misleading. On running ng build --prod I was told I had a genuine error in my AppModule.ts ("Reference to a local (non-exported) symbols are not supported in decorators"). Fixing that issue fixed the error messages in ng serve and ng build.
Only way to get this working was to reproduce the steps from @evolkmann
I had same error. Better to have a permanent fix rather than deleting module and reinstalling them again.
Still having no success with this. I've followed the steps outlined by @evolkmann and still get this same error. One thing I notice is that new CLI projects will do an AOT build just fine. The project I'm having this issue with was originally started using SystemJS without the CLI. Later on into the project we switched it over to start building through the angular-cli and completely removed SystemJS. I suspect that this issue can happen with a project created with an earlier version of the CLI installed, and then upgrading it to the latest. I did go through our project and made sure my .angular-cli.json and tsconfig files matched what a new project created through the CLI has with no success.
I've got the same issue as @willisd2 Just upgraded and didn't change any of my code
I followed the steps quoted from @JinsPeter , and it was good here.
my case My problem is in the incompatibility of the webpack, it follows the steps for solution:
remove the node_modules folder
rm -rf node_modules
remove the webpack
npm remove webpack
clean npm cahe
npm cache clean --force
install the latest version of angular cli
npm install --save-dev @angular/cli@latest
install the dependencies
npm install
now it's just testing
npm start our ng serve
This issue seems to be caused by having webpack listed in your project package.json directly. I'm sorry to say that this isn't supported. When you install more than one version of webpack it can cause a lot of problems.
If you have webpack listed in your package.json, you should follow these steps to remove it:
npm uninstall webpack --save
rm -rf node_modules package-lock.json
npm install
@filipesilva what about people not using CLI? You have some advice / feedback please?
@samvloeberghs if you're using @ngtools/webpack directly you should be ok with having webpack. Do you have a reproduction I can look at?
@filipesilva This should not be closed as removing webpack has no effect on this issue for me. Webpack, at one point in time was included in my package.json, but has since been removed, and removed using the steps you outlined above. I still experience this issue and so do new members of my team that end up pulling the project down fresh (without webpack in the package.json) and installing everything including NodeJS from the ground up. The following are the contents of my package.json if it helps:
{
"name": "ride",
"version": "1.0.0",
"description": "Package definitions for the RIDE application.",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"coverage": "lite-server --baseDir=\"./wwwroot/coverage\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@angular/animations": "5.1.2",
"@angular/cdk": "5.0.3",
"@angular/common": "5.1.2",
"@angular/compiler": "5.1.2",
"@angular/core": "5.1.2",
"@angular/flex-layout": "2.0.0-beta.12",
"@angular/forms": "5.1.2",
"@angular/http": "5.1.2",
"@angular/material": "5.0.3",
"@angular/platform-browser": "5.1.2",
"@angular/platform-browser-dynamic": "5.1.2",
"@angular/router": "5.1.2",
"angular2-text-mask": "8.0.4",
"core-js": "2.5.3",
"hammerjs": "2.0.8",
"jquery": "3.2.1",
"rxjs": "5.5.6",
"slick-carousel": "1.8.1",
"text-mask-addons": "3.7.1",
"web-animations-js": "2.3.1",
"whatwg-fetch": "2.0.3",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "1.6.3",
"@angular/compiler-cli": "5.1.2",
"@angular/language-service": "5.1.2",
"@types/arcgis-js-api": "^4.6.0",
"@types/core-js": "^0.9.43",
"@types/google.visualization": "0.0.35",
"@types/jasmine": "^2.8.3",
"@types/jquery": "^3.2.17",
"@types/node": "^8.5.2",
"@types/slick-carousel": "^1.6.32",
"canonical-path": "0.0.2",
"child_process": "1.0.2",
"codelyzer": "4.0.2",
"concurrently": "^3.5.1",
"del": "^3.0.0",
"delete": "1.1.0",
"gulp": "^3.9.1",
"gulp-change": "1.0.0",
"gulp-concat": "^2.6.1",
"gulp-cssmin": "^0.2.0",
"gulp-delete-directory-files": "^0.0.2",
"gulp-downloader": "^1.0.4",
"gulp-htmlmin": "^4.0.0",
"gulp-install": "^1.1.0",
"gulp-less": "3.4.0",
"gulp-less-to-scss": "^0.0.9",
"gulp-path": "^4.0.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-savefile": "0.1.1",
"gulp-uglify": "^3.0.0",
"http-server": "^0.10.0",
"jasmine-core": "2.8.0",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-coverage-istanbul-reporter": "1.3.3",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-spec-reporter": "^0.0.32",
"lite-server": "^2.3.0",
"lodash": "^4.17.4",
"merge-stream": "^1.0.1",
"node-powershell": "3.3.1",
"path": "^0.12.7",
"protractor": "^5.2.2",
"rimraf": "^2.6.2",
"ts-node": "4.1.0",
"tslint": "5.8.0",
"typescript": "2.4.2"
},
"repository": {}
}
Edit: json formatting