简体   繁体   English

未找到“AppModule”的 NgModule 元数据

[英]No NgModule metadata found for 'AppModule'

I have checked for several times but not sure what missing in AppModule.ts I have another module for AppRoutingModule.ts我已经检查了好几次,但不确定 AppModule.ts 中缺少什么我有 AppRoutingModule.ts 的另一个模块

Error :错误 :

C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web>ng build
Date: 2017-11-26T14:01:44.636Z
Hash: 3222da75cdc5af92bdb9
Time: 8949ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 303 bytes [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 323 bytes [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 11.4 kB [initial] [rendered]

ERROR in Error:错误中的错误:

No NgModule metadata found for 'AppModule'.
    at NgModuleResolver.resolve (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler\bundles\compiler.umd.js:20111:23)
    at CompileMetadataResolver.getNgModuleMetadata (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler\bundles\compiler.umd.js:15101:60)
    at visitLazyRoute (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler\bundles\compiler.umd.js:29995:104)
    at AotCompiler.listLazyRoutes (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler\bundles\compiler.umd.js:29963:20)
    at AngularCompilerProgram.listLazyRoutes (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler-cli\src\transformers\program.js:157:30)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@angular\compiler-cli\src\ngtools_api.js:44:36)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:247:66)
    at Promise.resolve.then.then (C:\Ravidas\Visual.Studio\Publish Health\Club.90.Web\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:538:50)

AppModule.ts AppModule.ts

 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { ChartsModule } from 'ng2-charts/ng2-charts'; import { Chart } from 'chart.js'; // Register 'Route Module' in main AppModule import { AppRoutingModule } from './route.config/app-routing.module'; /// All Custom Component Registerd here import { AppComponent } from './app.component'; import { HeaderComponent } from './header/header.component'; import { FooterComponent } from './footer/footer.component'; import { LoginFormComponent } from './login-form/login-form.component'; import { ForgetPasswordComponent } from './login-form/forgetPassword.component'; // import { DashboardComponent } from './dashboard/dashboard.component'; import { LoadingComponent } from './header/loading.component'; import { UserMenuComponent } from './dashboard/user.menu.component'; import { UserDashComponent } from './user/user.dash.component'; import { UserFeedComponent } from './user/user.feed.component'; import { BodyMeasurementComposiotnComponent } from './user/body.measurement.component'; import { UserGalleryComponent } from './user/user.gallery.component'; import { CustomerBodyDetailComponent } from './user/customer.body.detail.component'; import { AdminMenuComponent } from './admin/admin.menu.component'; import { AdminDashComponent } from './admin/admin.dash.component'; import { CustmoersComponent } from './admin/customers.component'; import { EditCustomerComponent } from './admin/edit.customer.component'; import { AddCustomerComponent } from './admin/add.customer.component'; import { MembershipPlanComponent } from './admin/membershipPlan.component'; import { AddMembershipPlanComponent } from './admin/add.membershipPlan.component'; import { EditMembershipPlanComponent } from './admin/edit.membershipPlan.component'; import { MembershipModalComponent } from './admin/membership.modal.component'; // Registered all Pipes import { SearchPipe } from './pipes/search.pipe'; // Registered all services import { CommonService } from './services/common.service'; import { UserProfile } from './services/user.profile'; import { UserService } from './services/user.service'; import { CustomerService } from './services/customer.service'; import { MembershipPlanService } from './services/membershipPlan.service'; import { MembershipDetailService } from './services/membershipdetail.service'; import { CustomerBodyDetailService } from './services/customer.body.detail.service'; import { DailyCustomerFeedService } from './services/daily.customer.feed.service'; import { MonthlyCustomerFeedService } from './services/monthly.customer.feed.service'; import { ManageCustomerService } from './services/manage.customer.service'; @NgModule({ imports: [ BrowserModule , FormsModule , ReactiveFormsModule , HttpModule , AppRoutingModule /// Routing Mdoule added , ChartsModule ], declarations: [ AppComponent , LoadingComponent , HeaderComponent , FooterComponent , LoginFormComponent , ForgetPasswordComponent // User Components , UserMenuComponent , UserDashComponent , UserFeedComponent , BodyMeasurementComposiotnComponent , UserGalleryComponent , CustomerBodyDetailComponent // Admin Components , AdminMenuComponent , AdminDashComponent , CustmoersComponent , EditCustomerComponent , AddCustomerComponent , MembershipPlanComponent , AddMembershipPlanComponent , EditMembershipPlanComponent , MembershipModalComponent // Pipes , SearchPipe ], providers: [ CommonService , UserProfile , UserService , CustomerService , MembershipPlanService , MembershipDetailService , CustomerBodyDetailService , DailyCustomerFeedService, , MonthlyCustomerFeedService , ManageCustomerService ], bootstrap: [AppComponent] }) export class AppModule { }

AppRoutingModule.ts AppRoutingModule.ts

 import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { AuthGuard } from '../auth.guard'; ///// All Custom Component Registerd here import { LoginFormComponent } from '../login-form/login-form.component'; import { ForgetPasswordComponent } from '../login-form/forgetPassword.component'; import { UserDashComponent } from '../user/user.dash.component'; import { UserFeedComponent } from '../user/user.feed.component'; import { BodyMeasurementComposiotnComponent } from '../user/body.measurement.component'; import { UserGalleryComponent } from '../user/user.gallery.component'; import { CustomerBodyDetailComponent } from '../user/customer.body.detail.component'; import { CustmoersComponent } from '../admin/customers.component'; import { AdminDashComponent } from '../admin/admin.dash.component'; import { AddCustomerComponent } from '../admin/add.customer.component'; import { EditCustomerComponent } from '../admin/edit.customer.component'; import { MembershipPlanComponent } from '../admin/membershipPlan.component'; import { AddMembershipPlanComponent } from '../admin/add.membershipPlan.component'; import { EditMembershipPlanComponent } from '../admin/edit.membershipPlan.component'; const routes: Routes = [ { path: 'login', component: LoginFormComponent }, { path: 'forgot-Password', component: ForgetPasswordComponent }, { path: 'customer/detail', component: CustomerBodyDetailComponent, canActivate: [AuthGuard] }, { path: 'feeds', component: UserFeedComponent, canActivate: [AuthGuard] }, { path: 'user/dashboard', component: UserDashComponent, canActivate: [AuthGuard], }, { path: 'body/measurement', component: BodyMeasurementComposiotnComponent, canActivate: [AuthGuard] }, { path: 'gallery', component: UserGalleryComponent, canActivate: [AuthGuard] }, { path: 'admin/dashboard', component: AdminDashComponent, canActivate: [AuthGuard] }, { path: 'customers', component: CustmoersComponent, canActivate: [AuthGuard] }, { path: 'customer/create', component: AddCustomerComponent }, { path: 'customer/edit/:id', component: EditCustomerComponent, canActivate: [AuthGuard] }, { path: 'membership/plans', component: MembershipPlanComponent, canActivate: [AuthGuard] }, { path: 'membership/plan/create', component: AddMembershipPlanComponent, canActivate: [AuthGuard] }, { path: 'mebership/plan/edit/:id', component: EditMembershipPlanComponent, canActivate: [AuthGuard] }, { path: '', redirectTo: '/login', pathMatch: 'prefix' }, ]; @NgModule({ imports: [RouterModule.forRoot(routes)], providers: [ AuthGuard ], exports: [RouterModule] }) export class AppRoutingModule { }

Main.ts主文件

 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));

Package.json包.json

 { "name": "club.90.web", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^5.0.0", "@angular/common": "^5.0.0", "@angular/compiler": "^5.0.0", "@angular/core": "^5.0.0", "@angular/forms": "^5.0.0", "@angular/http": "^5.0.0", "@angular/platform-browser": "^5.0.0", "@angular/platform-browser-dynamic": "^5.0.0", "@angular/router": "^5.0.0", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "ng2-charts": "^1.6.0", "rxjs": "^5.5.2", "zone.js": "^0.8.14" }, "devDependencies": { "@angular/cli": "1.5.4", "@angular/compiler-cli": "^5.0.0", "@angular/language-service": "^5.0.0", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "codelyzer": "^4.0.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", "ts-node": "~3.2.0", "tslint": "~5.7.0", "typescript": "~2.4.2" } }

Why I am getting No NgModule Metadata for 'AppModule'?为什么我没有收到“AppModule”的 NgModule 元数据?

AppModule.ts AppModule.ts

 , DailyCustomerFeedService, , MonthlyCustomerFeedService

There was an extra comma added while adding services inside provider.在 provider 中添加服务时添加了一个额外的逗号。 It frustrated me a lot and took hole day to identify it.这让我很沮丧,花了一天的时间来识别它。

Similarly to @Ravidas Shiudkar answer I had to fix some tslint errors.与@Ravidas Shiudkar 的回答类似,我必须修复一些 tslint 错误。 For example: missing semicolons, whitespace, double to single quotes around my project and mainly in app.module.ts.例如:缺少分号、空格、双引号到单引号围绕我的项目,主要是在 app.module.ts 中。

我不得不删除我现有的 typescript 版本 2.5.3 并在数小时试图弄清楚之后安装 typescript@2.6.2。

I finally resolved this issue.我终于解决了这个问题。 Resolution below.分辨率如下。 :-) :-)

Update the Angular CLI version to latest – as of today it's 1.7.4将 Angular CLI 版本更新为最新版本——截至今天,它是 1.7.4

  • how to check the version of Angular CLI如何检查 Angular CLI 的版本

    ng --version ng --version

  • Type the following command输入以下命令

    npm remove @angular/cli npm 删除 @angular/cli

    npm install --save-dev@angular/cli@latest npm install --save-dev@angular/cli@latest

-Make sure that webpack version is 3.11.0 - 确保 webpack 版本为 3.11.0

npm list webpack npm 列表 webpack

  • If not then run the following command.如果没有,则运行以下命令。

    npm remove webpack npm 删除 webpack

    npm install webpack@3.11.0 npm 安装 webpack@3.11.0

In my case problem was caused by在我的情况下,问题是由

skipCodeGeneration: true跳过代码生成:真

in

  plugins: [
    new AngularCompilerPlugin({
      mainPath: "./src/main.ts",
      tsConfigPath: "./tsconfig.app.json",
      skipCodeGeneration: !AOT
    }),
  ],

so, changing version of @ngtools/webpack package saved my day所以,更改@ngtools/webpack 包的版本拯救了我的一天

npm uninstall @ngtools/webpack npm卸载@ngtools/webpack

npm install @ngtools/webpack@6.0.0-beta.5 npm install @ngtools/webpack@6.0.0-beta.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到“ AppModule”的NgModule元数据中的错误 - ERROR in No NgModule metadata found for 'AppModule' 错误:找不到“ AppModule”的NgModule元数据 - Error: No NgModule metadata found for 'AppModule' 错误:找不到'AppModule'的NgModule元数据 - Error: No NgModule metadata found for 'AppModule' 错误:找不到“ AppModule”的NgModule元数据。 在另一台机器上 - Error: No NgModule metadata found for 'AppModule'. on another machine 找不到“AppModule”Angular 6.1.0 的 NgModule 元数据中的错误 - ERROR in No NgModule metadata found for 'AppModule' Angular 6.1.0 在“ AppModule”的NgModule元数据中找不到Angular 7错误 - Angular 7 ERROR in No NgModule metadata found for 'AppModule' 编译器失败 - 找不到“AppModule”的 NgModule 元数据中的错误 - Compiler fails - ERROR in No NgModule metadata found for 'AppModule' 找不到“AppModule”ngx-rocket metronic 主题的 NgModule 元数据中的错误 - ERROR in No NgModule metadata found for 'AppModule' ngx-rocket metronic theme 带有 Angular 的 Docker 给出错误“找不到用于‘AppModule’的 NgModule 元数据中的错误”。 - Docker with Angular giving error "ERROR in No NgModule metadata found for 'AppModule'." 找不到“ AppModule”的NgModule元数据中的错误。 和webpack:编译失败 - ERROR in No NgModule metadata found for 'AppModule'. and webpack: Failed to compile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM