Our dev team recently updated an Angular 5 project to Angular 7. I've downloaded the repo and I'm trying to build the source, however when I run the ng build command I get a ERROR in No NgModule metadata found for 'AppModule'.
If I run the ng --version command it shows the following:
- Angular CLI: 7.3.6
- Node: 11.10.0
- OS: win32 x64
- Angular: 7.2.10
The app.module.ts file is:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AdminComponent } from './layout/admin/admin.component';
import { AdminComponent1 } from './layout/admin1/estimate.component';
import { AuthComponent } from './layout/auth/auth.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SharedModule } from './shared/shared.module';
import { MenuItems } from './shared/menu-items/menu-items';
import { BreadcrumbsComponent } from './layout/admin/breadcrumbs/breadcrumbs.component';
import { ServicesProvider } from '../providers/services';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AuthGuardService } from './activate-guard';
import { AuthLoginService } from './deactivate-guard';
import { SupperAdmin } from './supperadmin-guard';
import { NgProgressModule } from 'ngx-progressbar';
import {SimpleNotificationsModule} from 'angular2-notifications';
import { ConfigService } from '../assets/config/ConfigService';
@NgModule({
declarations: [
AppComponent,
AdminComponent,
AdminComponent1,
AuthComponent,
BreadcrumbsComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
AppRoutingModule,
SharedModule,
NgProgressModule,
SimpleNotificationsModule.forRoot(),
BrowserModule,
],
providers: [MenuItems, ServicesProvider, AuthGuardService, SupperAdmin, AuthLoginService, NgProgressModule, ConfigService],
bootstrap: [AppComponent]
})
export class AppModule { }
and the main.ts file is:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
And the index.html is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome</title>
<base href="/">
<!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=xxx"></script>
<!-- <script src="https://maps.googleapis.com/maps/api/js"
async defer></script> -->
<!-- <script src="../src/assets/js/pdf.js"></script>
<script src="../src/assets/js/pdf.worker.js"></script> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="Visual Estimator" />
<meta name="keywords" content="visualestimator" />
<meta name="author" content="phoenixcoded" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
</style>
<!-- Google font-->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/ng2-toastr.css" rel="stylesheet" />
</head>
<body>
<app-root>
<div class="theme-loader">
<div class="loader-track">
<div class="preloader-wrapper">
<div class="spinner-layer spinner-blue">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
<div class="spinner-layer spinner-red">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
<div class="spinner-layer spinner-yellow">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
<div class="spinner-layer spinner-green">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>
</div>
</app-root>
</body>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-image/v0.0.4/leaflet-image.js'></script>
<script>
</script>
</html>
And the angular.json file:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"mega-able": {
"root": "",
"sourceRoot": "src",
"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": [
"src/assets",
"src/favicon.ico",
"src/marker-icon.png",
"src/marker-icon-2x.png"
],
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"node_modules/bootstrap/scss/bootstrap.scss",
"node_modules/font-awesome-scss/scss/font-awesome.scss",
"src/assets/images/zommer/leaflet/dist/leaflet.css",
"src/assets/images/zommer/leaflet-draw-toolbar/dist/leaflet.draw-toolbar.css",
"src/assets/images/zommer/leaflet-toolbar/dist/leaflet.toolbar.css",
"src/assets/images/zommer/leaflet-draw/dist/leaflet.draw-src.css",
"src/scss/style.scss"
],
"scripts": [
"src/assets/images/zommer/jquery.min.js",
"src/assets/images/zommer/bootstrap.min.js",
"src/assets/images/zommer/leaflet/dist/leaflet-src.js",
"src/assets/images/zommer/leaflet/dist/leaflet.rotatedMarker.js",
"src/assets/images/zommer/leaflet-toolbar/dist/leaflet.toolbar-src.js",
"src/assets/images/zommer/leaflet-draw/dist/leaflet.draw-src.js",
"src/assets/images/zommer/leaflet-draw-toolbar/dist/leaflet.draw-toolbar.js",
"src/assets/images/zommer/color.js",
"src/assets/images/zommer/pdf.js",
"src/assets/images/zommer/pdf.worker.js",
"src/assets/images/zommer/leafletfunction.js"
]
},
"configurations": {
"prod": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "mega-able:build"
},
"configurations": {
"prod": {
"browserTarget": "mega-able:build:prod"
},
"production": {
"browserTarget": "mega-able:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "mega-able: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": [
"src/assets/images/zommer/jquery.min.js",
"src/assets/images/zommer/bootstrap.min.js",
"src/assets/images/zommer/leaflet/dist/leaflet-src.js",
"src/assets/images/zommer/leaflet/dist/leaflet.rotatedMarker.js",
"src/assets/images/zommer/leaflet-toolbar/dist/leaflet.toolbar-src.js",
"src/assets/images/zommer/leaflet-draw/dist/leaflet.draw-src.js",
"src/assets/images/zommer/leaflet-draw-toolbar/dist/leaflet.draw-toolbar.js",
"src/assets/images/zommer/color.js",
"src/assets/images/zommer/pdf.js",
"src/assets/images/zommer/pdf.worker.js",
"src/assets/images/zommer/leafletfunction.js"
],
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"node_modules/bootstrap/scss/bootstrap.scss",
"node_modules/font-awesome-scss/scss/font-awesome.scss",
"src/assets/images/zommer/leaflet/dist/leaflet.css",
"src/assets/images/zommer/leaflet-draw-toolbar/dist/leaflet.draw-toolbar.css",
"src/assets/images/zommer/leaflet-toolbar/dist/leaflet.toolbar.css",
"src/assets/images/zommer/leaflet-draw/dist/leaflet.draw-src.css",
"src/scss/style.scss"
],
"assets": [
"src/assets",
"src/favicon.ico",
"src/marker-icon.png",
"src/marker-icon-2x.png"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"mega-able-e2e": {
"root": "e2e",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "mega-able:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "mega-able",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss"
},
"@schematics/angular:directive": {
"prefix": "app"
}
}
}
Below are all the various things I have tried based on Google searches. All the commands were run from a Git Bash window unless otherwise specified:
- npm install -g @angular/cli
- npm install @angular/cli
- ng update @angular/cli
- ng update
- ng update @angular/cli @angular/core
- ng build
The same issue about the NgModule metadata was still present. Next I tried the following:
- npm remove webpack
- npm install –save-dev @angular/cli@latest
- npm cache clean –force
- npm install
- npm install –save-dev @angular/cli@latest
- ng build
Issue persisted. Next:
- Manually deleted the node_modules folder
- npm install
- ng build
Issue persisted. Next:
- npm i -g @angular/cli@latest
- Manually deleted node_modules folder
- npm cache clear –force
- npm cache verify
- npm install
- npm uninstall webpack
- npm install –save-dev –save-exact @angular/cli@latest
- ng build
Issue persisted. Next:
- Manually deleted the node_modules folder
- Manually deleted the package-lock.json file
- npm install
- ng build
Issue persisted. Next:
- npm remove webpack
- npm install –save-dev @angular/cli@latest
- ng build
Issue persisted. Next:
- npm cache clean –force
- npm install
- npm install –save-dev @angular/cli@latest
- ng build
Issue persisted. Next:
- Manually deleted the node_modules folder
- Manually deleted the package-lock.json file
- npm cache clean –force
- npm install
- npm install –save-dev @angular/cli@latest
Issue persisted. Next:
- Opened project in Visual Studio code
- In the terminal window ran ng s
- Confirmed compilation error
- Opened the app.component.ts file
- Added a blank space, removed it, and saved
- Project automatically recompiled
- Successfully access the site at http://localhost:4200
- Closed Visual Studio Code
- From a Git Bash window ran ng serve
- Project failed to compile
- Re-opened Visual Studio Code
- Ran ng serve from terminal window – error persisted
- Resaved the app.component.ts file
- Successfully accessed the site at http://localhost:4200
- Restarted Visual Studio Code
- Ran ng build from terminal window in Visual Studio Code – error returned
- Resaved the app.component.ts file
- Reran ng build command – error persisted
I'm at a lost of what else to try at this point and the dev team is off until at Tuesday for a holiday so any help or suggestions would be greatly appreciated as I'm under some time constraints. Thank you in advance for any help.