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

"ERROR in No NgModule metadata found for 'AppModule'." when upgrading to Angular CLI 6.x

Open lehtiniemi opened this issue 8 years ago • 31 comments

Versions

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.10
@angular-devkit/build-angular     0.5.10
@angular-devkit/build-optimizer   0.4.9
@angular-devkit/core              0.5.10 (cli-only)
@angular-devkit/schematics        0.5.10 (cli-only)
@angular/cdk                      5.2.5
@angular/cli                      6.0.0-rc.7
@angular/material                 5.2.5
@angular/platform-server          5.2.10
@ngtools/json-schema              1.2.0
@ngtools/webpack                  6.0.0-rc.8
@schematics/angular               0.5.10 (cli-only)
@schematics/update                0.5.10
rxjs                              5.5.10
typescript                        2.8.3
webpack                           4.6.0

Repro steps

  • Installed 6.0.0-rc.5
  • Migrated project from 1.7.4 with RC5, command ng update @angular/cli --migrate-only -from=1 as suggested by the installer
  • Tried to run ng serve
  • Got error "ERROR in No NgModule metadata found for 'AppModule'."
  • Tried to upgrade to rc7
  • Serve still gives same error

Observed behavior

ng serve produces

Date: 2018-04-28T15:41:34.299Z
Hash: bfbd0778795913efc41e
Time: 10484ms
chunk {main} main.js, main.js.map (main) 1.95 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 694 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.4 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 1.13 MB  [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.93 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 325 kB [initial] [rendered]

ERROR in No NgModule metadata found for 'AppModule'.
i 「wdm」: Failed to compile.

Desired behavior

I expected the compiler to compile my project without errors as it did with 1.7.4

Mention any other details that might be useful (optional)

In this report my typescript version was unsupportedly high, but I get the same error after running: npm install typescript@'>=2.4.2 <2.7.0'

angular.json: { "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "Paperi 0": { "root": "", "projectType": "application", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "tsConfig": "src/tsconfig.app.json", "polyfills": "src/polyfills.ts", "assets": [ { "glob": "**/*", "input": "src/assets", "output": "/./assets" }, { "glob": "favicon.ico", "input": "src", "output": "/" } ], "styles": [ "src/styles.scss", "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/font-awesome/css/font-awesome.css", "node_modules/froala-editor/css/froala_editor.pkgd.min.css", "node_modules/lightbox2/dist/css/lightbox.min.css", "node_modules/ng2-dnd/bundles/ng2-dnd.umd.js" ], "scripts": [ "node_modules/jquery/dist/jquery.js", "node_modules/popper.js/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.js", "node_modules/froala-editor/js/froala_editor.pkgd.min.js", "node_modules/lightbox2/dist/js/lightbox.min.js", "node_modules/crypto-js/crypto-js.js" ] }, "configurations": { "production": { "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "Paperi 0:build" }, "configurations": { "production": { "browserTarget": "Paperi 0:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "Paperi 0:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "karmaConfig": "./karma.conf.js", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "scripts": [ "node_modules/jquery/dist/jquery.js", "node_modules/popper.js/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.js", "node_modules/froala-editor/js/froala_editor.pkgd.min.js", "node_modules/lightbox2/dist/js/lightbox.min.js", "node_modules/crypto-js/crypto-js.js" ], "styles": [ "src/styles.scss", "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/font-awesome/css/font-awesome.css", "node_modules/froala-editor/css/froala_editor.pkgd.min.css", "node_modules/lightbox2/dist/css/lightbox.min.css", "node_modules/ng2-dnd/bundles/ng2-dnd.umd.js" ], "assets": [ { "glob": "**/*", "input": "src/assets", "output": "/./assets" }, { "glob": "favicon.ico", "input": "src", "output": "/" } ] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" ], "exclude": [] } } } }, "Paperi 0-e2e": { "root": "", "projectType": "application", "cli": {}, "schematics": {}, "architect": { "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "./protractor.conf.js", "devServerTarget": "Paperi 0:serve" } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "e2e/tsconfig.e2e.json" ], "exclude": [] } } } } }, "cli": {}, "schematics": { "@schematics/angular:component": { "prefix": "app", "styleext": "scss" }, "@schematics/angular:directive": { "prefix": "app" } } }

package.json: { "name": "nordic-sounds", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build --prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "build-newspaper-1": "ng build --prod --build-optimizer -aot --base-href /dev/sanomalehti-demo/", "serve-nordic-sounds": "ng serve --app nordic-sounds", "build-nordic-sounds": "ng build --prod --app nordic-sounds --output-path ./dist/nordic-sounds", "build-nordic-sounds-beta": "ng build --prod --app nordic-sounds --base-href /beta/ --output-path ./dist/nordic-sounds-beta", "serve-sanomalehti-demo": "ng serve --app sanomalehti-demo", "build-sanomalehti-demo": "ng build --prod --build-optimizer --app sanomalehti-demo --base-href /dev/sanomalehti-demo/ --output-path ./dist/sanomalehti-demo", "bundle-report-sanomalehti-demo": "webpack-bundle-analyzer dist/sanomalehti-demo/stats.json", "sourcemaps-sanomalehti-demo": "ng build --prod --sourcemaps --app sanomalehti-demo --base-href /dev/sanomalehti-demo/ --output-path ./dist/sanomalehti-demo" }, "private": true, "dependencies": { "@angular/animations": "5.2.8", "@angular/cdk": "^5.2.5", "@angular/common": "5.2.8", "@angular/compiler": "5.2.8", "@angular/core": "5.2.8", "@angular/forms": "5.2.8", "@angular/http": "5.2.8", "@angular/material": "^5.2.5", "@angular/platform-browser": "5.2.8", "@angular/platform-browser-dynamic": "5.2.8", "@angular/platform-server": "^5.2.10", "@angular/router": "5.2.8", "@ng-bootstrap/ng-bootstrap": "^1.1.2", "@types/crypto-js": "^3.1.39", "@types/smoothscroll-polyfill": "^0.3.0", "ajv": "^6.4.0", "angular-2-local-storage": "^1.0.1", "angular-froala-wysiwyg": "^2.8.1", "angular2-lightbox": "^1.3.0", "angular2-tooltips": "^1.0.10", "bootstrap": "^4.1.0", "classlist.js": "^1.1.20150312", "core-js": "^2.5.5", "crypto-js": "^3.1.9-1", "dom-to-image": "^2.6.0", "font-awesome": "^4.7.0", "lightbox2": "^2.9.0", "mammoth": "^1.4.5", "md-tooltip": "0.0.1-alpha.1", "ng2-component-spinner": "^0.2.1", "ng2-dnd": "^5.0.2", "ng2-file-upload": "^1.3.0", "ng2-scroll-to-el": "^1.2.1", "ngx-bootstrap": "^1.9.1", "ngx-contextmenu": "^4.2.0", "popper": "^1.0.0", "popper.js": "^1.14.3", "raf": "^3.4.0", "rxjs": "^5.5.10", "smoothscroll-polyfill": "^0.4.3", "tether": "^1.4.4", "web-animations-js": "^2.3.1", "zone.js": "^0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.5.0", "@angular-devkit/build-optimizer": "^0.4.9", "@angular/cli": "^6.0.0-rc.7", "@angular/compiler-cli": "5.2.8", "@types/jasmine": "2.5.38", "@types/node": "^6.0.106", "codelyzer": "^4.3.0", "froala-editor": "^2.8.1", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", "karma-chrome-launcher": "~2.0.0", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^0.2.0", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "node-sass": "^4.9.0", "protractor": "^5.3.1", "raw-loader": "^0.5.1", "sass-loader": "^6.0.7", "source-map-explorer": "^1.5.0", "ts-node": "~2.0.0", "tslint": "^5.9.1", "typescript": "^2.8.3", "webpack-bundle-analyzer": "^2.11.1" } }

lehtiniemi avatar Apr 28 '18 15:04 lehtiniemi

Hi!

I dont think this changes makes sense but i tested anyway.. and didnt work =(

Here is the change: https://github.com/mariohmol/ng-brazil/compare/4c9a7d272f29...20955ef76f98

Here is the build error: https://travis-ci.org/mariohmol/ng-brazil/builds/448330078

mariohmol avatar Oct 30 '18 13:10 mariohmol

I upgrade to Angular7 and got the same error. Have tried all suggestions above but nothing worked in my case :(

ng build --project=admin --no-progress

Date: 2018-10-31T09:01:37.961Z
Hash: c852709f74070d0f5f6c
Time: 40952ms
chunk {main} main.js, main.js.map (main) 643 bytes [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 105 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 232 kB  [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.62 MB [initial] [rendered]

ERROR in No NgModule metadata found for 'AppModule'.
```

qmphan avatar Oct 31 '18 09:10 qmphan

I too have upgraded to Angular 7 and my setup has changed slightly from my fix mentioned above.

Angular CLI: 7.0.3 Node: 10.12.0 OS: win32 x64

Running @angular/[email protected]

I no longer require a reference to app.module.ts in my tsconfig.app.json file. It now looks like this:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": ["node"]
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

codingbadger avatar Oct 31 '18 09:10 codingbadger

I was working on a project, and it required me to add @types/jquery in include of tsconfig.json. Now i am getting this error

Date: 2018-10-31T09:01:37.961Z
Hash: c852709f74070d0f5f6c
Time: 40952ms
chunk {main} main.js, main.js.map (main) 643 bytes [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 105 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 232 kB  [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.62 MB [initial] [rendered]

ERROR in No NgModule metadata found for 'AppModule'.

Let me know if there is any workaround

Prabhjyotgambhir avatar Mar 15 '19 10:03 Prabhjyotgambhir

I solve the issue, in the file main.ts, I remove this part .catch(err => console.error(err)); and the final line is just: platformBrowserDynamic().bootstrapModule(AppModule);

JuanEstebanKatz avatar Apr 18 '19 18:04 JuanEstebanKatz

We are in a Hybrid app with angular-ts-decorator and angular-cli. As @rafidka said. It works when setting aot: false. Any permanent solution to this?

fasidOnGit avatar Jun 27 '19 14:06 fasidOnGit

Fixed it! I had to add entryModule in tsconfig.app.json file.

"angularCompilerOptions": {
    "entryModule": "./app/app.module#AppModule"
  }

No Need to set aot: false.

fasidOnGit avatar Jul 01 '19 05:07 fasidOnGit

I am getting same help me here.

[ng] chunk {es2015-polyfills} es2015-polyfills.js, es2015-polyfills.js.map (es2015-polyfills) 285 kB [initial] [rendered] [ng] chunk {main} main.js, main.js.map (main) 1.9 kB [initial] [rendered] [ng] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 93.2 kB [initial] [rendered] [ng] chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered] [ng] chunk {styles} styles.js, styles.js.map (styles) 65.8 kB [initial] [rendered] [ng] chunk {vendor} vendor.js, vendor.js.map (vendor) 327 kB [initial] [rendered] [ng] [ng] ERROR in No NgModule metadata found for 'AppModule'.

Ionic:

ionic (Ionic CLI) : 4.10.3 (C:\Users\admin\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : @ionic/angular 4.11.2 @angular-devkit/build-angular : 0.13.9 @angular-devkit/schematics : 7.3.9 @angular/cli : 7.3.9 @ionic/angular-toolkit : 1.5.1

Cordova:

cordova (Cordova CLI) : 9.0.0 ([email protected]) Cordova Platforms : android Cordova Plugins : no whitelisted plugins (0 plugins total)

System:

Android SDK Tools : 26.1.1 (C:\Users\admin\AppData\Local\Android\Sdk) NodeJS : v10.15.1 (C:\Program Files\nodejs\node.exe) npm : 6.4.1 OS : Windows 10

Just upgraded from 9.0.6 to 9.1.0 and still seeing the same issue.

The only thing that works for me is saving again the app.module.ts file while it is watching. Need a more permanent solution.

sebastianteres avatar Apr 02 '20 19:04 sebastianteres

Thanks for reporting this issue. However, you didn't provide sufficient information for us to understand and reproduce the problem. Please check out our submission guidelines to understand why we can't act on issues that are lacking important information.

If the problem persists, please file a new issue and ensure you provide all of the required information when filling out the issue template.

alan-agius4 avatar May 25 '20 13:05 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.