"ERROR in No NgModule metadata found for 'AppModule'." when upgrading to Angular CLI 6.x
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"
}
}
I'm still having this with the release version:
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, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.4.9
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0 (cli-only)
@angular/cdk 5.2.5
@angular/material 6.0.1
@angular/platform-server 5.2.10
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0 (cli-only)
@schematics/update 0.6.0
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
I can't compile, it always ends up with:
Date: 2018-05-08T14:11:12.824Z Hash: 02cf6c33a9793e065921 Time: 11557ms 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) 2.61 MB [initial] [rendered] chunk {vendor} vendor.js, vendor.js.map (vendor) 325 kB [initial] [rendered]
ERROR in No NgModule metadata found for 'AppModule'.
Please let me know if there are any details I can provide. This project compiles and builds without errors on Angular CLI 1.7.x
Here's the app.module if it helps:
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule, PreloadAllModules, NoPreloading } from '@angular/router';
import { RouteReuseStrategy } from '@angular/router';
import { CustomReuseStrategy } from './route-reuse-strategy';
import { AppComponent } from './app.component';
import { SearchResultsListComponent } from './search-results-list/search-results-list.component';
import { ItemPreviewVideoComponent } from './item-preview-video/item-preview-video.component';
import { ItemPreviewTextComponent } from './item-preview-text/item-preview-text.component';
import { ItemPreviewTitleComponent } from './item-preview-title/item-preview-title.component';
import { ItemDetailViewInlineLayout2Component } from './item-detail-view-inline-layout-2/item-detail-view-inline-layout-2.component';
import { ItemChildDetailViewInlineComponent } from './item-child-detail-view-inline/item-child-detail-view-inline.component';
import { ReaderPageLayout2Component } from './reader-page-layout-2/reader-page-layout-2.component';
import { ItemPreviewAudioComponent } from './item-preview-audio/item-preview-audio.component';
import { ItemPreviewNoneComponent } from './item-preview-none/item-preview-none.component';
import { ItemPreviewImageComponent } from './item-preview-image/item-preview-image.component';
import { ItemPreviewComponent } from './item-preview/item-preview.component';
// Pages
import { SearchPageComponent } from './search-page/search-page.component';
import { CartPageComponent } from './cart-page/cart-page.component';
import { StartPageComponent } from './start-page/start-page.component';
import { DataService } from './data-service/data.service';
import { SearchResultItemComponent } from './search-result-item/search-result-item.component';
import { LocalStorageModule } from 'angular-2-local-storage';
import { RouterOutletExtensionDirective } from './router-outlet-extension.directive';
import { ScrollToModule } from 'ng2-scroll-to-el';
import { SharedServicesModule } from './shared-services/shared-services.module';
import { InitializeService } from './initialize-service/initialize.service';
import { PreloadSelectedModulesList } from './custom-preload-strategy';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { SiteComponent } from './site/site.component';
import { PageTemplateComponent } from './page-template/page-template.component';
@NgModule({
declarations: [
AppComponent,
SearchPageComponent,
CartPageComponent,
SearchResultsListComponent,
ItemPreviewVideoComponent,
ItemPreviewTextComponent,
ItemPreviewTitleComponent,
ItemDetailViewInlineLayout2Component,
ItemChildDetailViewInlineComponent,
ReaderPageLayout2Component,
ItemPreviewAudioComponent,
ItemPreviewNoneComponent,
ItemPreviewImageComponent,
ItemPreviewComponent,
SearchResultItemComponent,
StartPageComponent,
RouterOutletExtensionDirective,
SiteComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
BrowserAnimationsModule,
SharedServicesModule.forRoot(),
ScrollToModule.forRoot(),
LocalStorageModule.withConfig({
prefix: 'app-root',
storageType: 'localStorage'
}),
RouterModule.forRoot([
{
path: ':siteId',
component: SiteComponent,
canActivate: [InitializeService],
/* Doesn't let the user leave the root until site settings have been loaded */
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'start'
},
{
path: 'start',
component: StartPageComponent
// canActivate: [InitializeService]
},
{
path: 'search',
component: SearchPageComponent,
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
{
path: 'search/:searchWords',
component: SearchPageComponent,
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
{
path: 'search/details/:id',
component: ReaderPageLayout2Component,
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
{
path: 'page/:id',
component: PageTemplateComponent,
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
{
path: 'login',
data: { preload: false },
loadChildren: "app/login/login.module#LoginModule",
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
{
path: 'admin',
data: { preload: false },
loadChildren: "app/admin/admin.module#AdminModule"
},
{
path: 'cart',
component: CartPageComponent,
/* Doesn't let the user leave the root until site settings have been loaded */
// canActivate: [InitializeService]
},
]
},
{
/** TODO: Lisää tähän NO ID -sivu **/
path: '**',
component: PageNotFoundComponent,
// pathMatch: 'full',
// redirectTo: '1/start'
}
],
{
preloadingStrategy: PreloadSelectedModulesList,
useHash: true
})
],
providers: [
DataService,
PreloadSelectedModulesList,
{ provide: RouteReuseStrategy, useClass: CustomReuseStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule { }
I am getting the exact same output / error, also after making the same upgrade.
Date: 2018-05-13T21:37:06.739Z Hash: 24441611d6ea08acfcc9 Time: 4451ms chunk {main} main.js, main.js.map (main) 2.18 kB [initial] [rendered] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 701 bytes [initial] [rendered] chunk {runtime} runtime.js, runtime.js.map (runtime) 5.4 kB [entry] [rendered] chunk {styles} styles.js, styles.js.map (styles) 19.9 kB [initial] [rendered] chunk {vendor} vendor.js, vendor.js.map (vendor) 326 kB [initial] [rendered]
ERROR in No NgModule metadata found for 'AppModule'.
same problem here
$ ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
14% building modules 36/38 modules 2 active …tstrap-md\scss\bootstrap\bootstrap.scssWARNING: The text-hide() mixin has been deprecated as of v4.1.0. It will be removed entirely in v5.
on line 10 of node_modules/angular-bootstrap-md/scss/bootstrap/mixins/_text-hide.scss, in mixin text-hide
from line 57 of node_modules/angular-bootstrap-md/scss/bootstrap/utilities/_text.scss
from line 14 of node_modules/angular-bootstrap-md/scss/bootstrap/_utilities.scss
from line 41 of stdin
Date: 2018-05-17T19:08:34.370Z Hash: 17a1f9847cfc9cf4d597 Time: 4154ms chunk {main} main.js, main.js.map (main) 1.99 kB [initial] [rendered] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 710 bytes [initial] [rendered] chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered] chunk {scripts} scripts.js, scripts.js.map (scripts) 381 kB [rendered] chunk {styles} styles.js, styles.js.map (styles) 476 kB [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.
same problem
Date: 2018-05-20T10:31:26.948Z Hash: 17a1f9847cfc9cf4d597 Time: 5178ms chunk {main} main.js, main.js.map (main) 1.94 kB [initial] [rendered] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 687 bytes [initial] [rendered] chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered] chunk {scripts} scripts.js, scripts.js.map (scripts) 381 kB [rendered] chunk {styles} styles.js, styles.js.map (styles) 475 kB [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.
I started having the same error after upgrading to Angular 6. It happens when I build production. The issue on my side seems to be related to enabling aot and buildOptimizer. When these are enabled, I get the issue. When I disable these two, the problem disappear. Here is my configuration:
"prod": {
"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"
}
]
}
Also started having the issue after upgrading to Angular 6, although it only occurs when aot is set to false (contrary to @rafidka's config). Configuration that causes the error:
"qa": {
"optimization": false,
"outputHashing": "all",
"sourceMap": false,
"extractCss": false,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": false,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.qa.ts"
}
]
}
We, too, are experiencing this issue, but only when AoT is disabled, e.g., ng build produces the error, but ng build --aot works fine. Is there anything we can do to help debugging it? ng build --verbose just prints the same error twice.
As an update, for us it appears that all users who experience this issue when building without AoT are Windows users. Linux and macOS users aren't seeing this.
I too am seeing this issue after upgrading from v5.2 to v6
Angular CLI: 6.0.8
Node: 8.11.2
OS: win32 x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Running ng build or ng serve produces the error ERROR in No NgModule metadata found for 'AppModule'.
However running ng build --aot or ng serve --aot does not.
A workaround for this is add the app.module.ts to the files array in your tsconfig.app.json
"files": [
"../src/app/app.module.ts"
]
You can then run ng build and ng serve without getting the error
@codingbadger thank you so much for this workaround! Hopefully it gets fixed really soon.
I can also confirm that the workaround suggested by @codingbadger works for our Windows users.
Another confirmation that the workaround suggested by @codingbadger works on windows
thank you @codingbadger , spent hours on this issue and was about to abandon our upgrade to angular 6.
Hope they fix this soon
@Airblader @richardscholten73 which version of Windows are you on? I'm on 8.1 but the workaround doesn't seem to work
@maartentibau windows 10
@Airblader @richardscholten73 I can confirm that upgrading my nodejs version to 9.x and removing my node_modules folder, the lock file and doing a clean npm i did solve the problem. I'm on Windows 8.1
I'm on the latest Angular CLI version, TS 2.8.4
I'm having this issue when i try to run a e2e test in travis.. if I run this local works as expected..
https://travis-ci.org/mariohmol/ng-brazil/builds/431752859
Maybe the problem i'm passing in this build might help to reproduce this error?
I'm having this issue on a Angular 6 to Angular 7 upgrade.
UPDATE: After upgrading to Node 10 from 9, and implementing the install using the old npm install method, instead of ngUpdate, I got a successful build.
Thanks for the solution of adding it app.module.ts in tsconfig.app.json. It worked for me as well.
Hey Guys, I just added this line "baseUrl": "../node_modules", on the tsconfig.app.json file under compilerOptions.... It worked fine for me with that....
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "../node_modules",
"types": []
} ...
You can see it here: https://github.com/angular/angular-cli/issues/10837