首页 > 解决方案 > 找不到模块的 NgModule 元数据中的错误('DeviceProfileConfigurationModule')

问题描述

ng serve 的 Cmd 输出

日期:2018-11-19T11:53:47.208Z
哈希:8b2719588798f3cae7c5
时间:17051ms
块 {main} main.js, main.js.map (main) 1.84 kB [初始] [渲染]
块 {polyfills} polyfills.js, polyfills.js.map (polyfills) 92.3 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {scripts} scripts.js, 脚本。 js.map (scripts) 1.08 MB [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.73 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor ) 318 kB [初始] [渲染]

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

将角度应用程序从角度 4 更新到角度 7 或 6 后出现上述错误,我尝试了以下步骤但无法正常工作。请问还有其他解决方案吗?

npm cache clean --force

npm install

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

请检查文件

> 包.json 文件

{
  "name": "asset-web",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build-prod": "node --max-old-space-size=8192 node_modules/@angular/cli/bin/ng build --prod --aot",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.5",
    "@angular/animations": "^7.0.4",
    "@angular/cdk": "^7.0.4",
    "@angular/common": "^7.0.4",
    "@angular/compiler": "^7.0.4",
    "@angular/core": "^7.0.4",
    "@angular/forms": "^7.0.4",
    "@angular/http": "^7.0.4",
    "@angular/material": "^7.0.4",
    "@angular/platform-browser": "^7.0.4",
    "@angular/platform-browser-dynamic": "^7.0.4",
    "@angular/router": "^7.0.4",
    "@ng-bootstrap/ng-bootstrap": "^4.0.0",
    "@swimlane/ngx-charts": "^10.0.0",
    "@swimlane/ngx-datatable": "10.2.3",
    "@types/file-saver": "0.0.1",
    "@types/googlemaps": "^3.30.16",
    "@types/xlsx": "0.0.36",
    "agm-core": "^1.0.0-beta.5",
    "angular-2-dropdown-multiselect": "^1.8.1",
    "angular-calendar": "^0.26.4",
    "angular-in-memory-web-api": "^0.7.0",
    "angular-resizable-element": "^3.2.2",
    "angular-tree-component": "^7.2.1",
    "angular2-datetimepicker": "^1.1.1",
    "angular2-google-map": "^0.1.8",
    "angular2-permission": "^0.1.3",
    "bootstrap": "^4.1.3",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.7",
    "crypto-js": "^3.1.9-1",
    "d3": "4.10.2",
    "d3-array": "^2.0.2",
    "d3-hierarchy": "1.1.5",
    "export-to-csv": "^0.1.2",
    "file-saver": "^1.3.8",
    "flag-icon-css": "2.9.0",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "intl": "1.2.5",
    "jquery": "^3.3.1",
    "jspdf": "^1.4.1",
    "jspdf-autotable": "^2.3.5",
    "leaflet-map": "0.2.1",
    "lodash": "^4.17.11",
    "moment": "^2.22.2",
    "ng-click-outside": "^2.4.1",
    "ng2-bootstrap-modal": "^1.0.1",
    "ng2-ckeditor": "^1.2.2",
    "ng2-completer": "1.6.3",
    "ng2-cookies": "^1.0.12",
    "ng2-daterangepicker": "^2.0.10",
    "ng2-dragula": "1.5.0",
    "ng2-popover": "0.0.14",
    "ng2-smart-table": "^1.3.5",
    "ng2-stomp-service": "^1.2.2",
    "ng2-validation": "4.2.0",
    "ngc-webpack": "^4.1.2",
    "ngx-bootstrap": "^2.0.5",
    "ngx-carousel": "^1.3.5",
    "ngx-color-picker": "^4.5.3",
    "ngx-datetime-picker": "^2.0.0",
    "ngx-file-drop": "^1.0.13",
    "ngx-mat-daterange-picker": "^1.1.4",
    "ngx-mydatepicker": "^2.4.9",
    "ngx-pagination": "3.0.3",
    "ngx-perfect-scrollbar": "4.9.6",
    "ngx-popover": "0.0.16",
    "ngx-toastr": "^9.1.1",
    "ngx-treeview": "^6.0.2",
    "popper.js": "^1.14.5",
    "primeng": "^4.3.0",
    "rxjs": "^6.3.3",
    "sockjs-client": "^1.3.0",
    "stompjs": "^2.3.3",
    "ts-xlsx": "0.0.11",
    "tslib": "^1.9.3",
    "web-animations-js": "2.3.1",
    "widgster": "1.0.0",
    "xlsx": "^0.11.19",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.10.6",
    "@angular/cli": "^7.0.6",
    "@angular/compiler-cli": "^7.0.4",
    "@angular/language-service": "^5.2.11",
    "@types/jasmine": "^2.8.12",
    "@types/jasminewd2": "^2.0.6",
    "@types/jquery": "^3.3.22",
    "@types/lodash": "^4.14.118",
    "@types/node": "^6.14.2",
    "codelyzer": "^4.5.0",
    "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.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "^3.1.6"
  }
}

> 我的 Approutes.ts 文件

import { AuthGuard } from './guards/auth.guard';
import { RouterModule, Routes, PreloadAllModules } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { LoginComponent } from './pages/login/login/login.component';
import { AuthenticatedComponent } from './authenticated/authenticated.component';
import { MainComponent } from './common/main/main.component';
import { UserTrackingComponent } from './pages/user-tracking/user-tracking.component';
import { MapComponent } from './pages/customerconfiguration/map/map.component';
import { IPermissionGuardModel, PermissionGuard } from '../../node_modules/angular2-permission';
import { UsermasterComponent } from './pages/customerconfiguration/usermaster/usermaster.component';
import { DeviceInventorySidebarComponent } from './pages/inventory/device-inventory-sidebar/device-inventory-sidebar.component';
import { GroupComponent } from './pages/group-definition/group/group.component';
import { GroupDefinitionComponent } from './pages/group-definition/group-definition/group-definition.component';
import { DeviceProfileComponent } from './pages/device-profile/device-profile/device-profile.component';
import { AlertManagementSidebarComponent } from './pages/alert/alert-management-sidebar/alert-management-sidebar.component';
export const AppRoutes: Routes = [
  {
    path: "",
    canActivate: [AuthGuard],
    component: AuthenticatedComponent,
    children: [
      {
        path: "",
        component: MainComponent,
        loadChildren: "./pages/dashboard.module#DashboardModule",
      },

      {
        path: 'profileconfiguration',
        pathMatch: "full",
        data: {
          Permission: {
            Only: ['ROLE_CREATE_DEVICE_PROFILE', 'ROLE_UPDATE_DEVICE_PROFILE', 'ROLE_VIEW_DEVICE_PROFILE'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        loadChildren: './pages/device-profile-configuration/device-profile-configuration.module#DeviceProfileConfigurationModule'

      },



      {
        path: 'profile',
        canActivate: [AuthGuard, PermissionGuard],
        component: DeviceProfileComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_DEVICE_PROFILE', 'ROLE_UPDATE_DEVICE_PROFILE', 'ROLE_VIEW_DEVICE_PROFILE'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        loadChildren: './pages/device-profile/device-profile.module#DeviceProfileModule'
      },


    ]

  },
  {
    path: "login",
    component: LoginComponent
  },
  {
    redirectTo: "",
    path: "**",
  }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(AppRoutes, {
  preloadingStrategy: PreloadAllModules,
});

设备配置文件配置文件

import { AuthGuard } from "../../guards/auth.guard";
import { PermissionGuard, IPermissionGuardModel } from "../../../../node_modules/angular2-permission";
import { LoraComponent } from "./lora/lora.component";
import { HrComponent } from "./hr/hr.component";
import { SkinTempComponent } from "./skin-temp/skin-temp.component";
import { FallComponent } from "./fall/fall.component";
import { BatteryComponent } from "./battery/battery.component";
import { NgModule, ModuleWithProviders } from "../../../../node_modules/@angular/core";
import { CommonModule } from "@angular/common";
import { RouterModule } from "@angular/router";
import { DeviceProfileConfigurationComponent } from "./device-profile-configuration/device-profile-configuration.component";
import { Common_Module } from "../../common/common-module";
import { ReactiveFormsModule, FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { MatButtonModule, MatCheckboxModule, MatRadioModule, MatAutocompleteModule, MatInputModule, MatDialogModule, MatSidenavModule, MatStepperModule, MatSelectModule, MatTooltipModule, MatSlideToggleModule } from "@angular/material";

export const routes = [
    {
      path: "",
      canActivate: [AuthGuard, PermissionGuard],
      component: DeviceProfileConfigurationComponent,
      redirectTo: "lora/add",pathMatch: 'full'
    },
     {
        path: "hr",
        redirectTo: "hr/add",
        pathMatch: 'full'
      }, {
        path: 'hr/:action',
        canActivate: [AuthGuard, PermissionGuard],
        component: HrComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_HEART_RATE_LEVEL_CONFIGURATION', 'ROLE_UPDATE_HEART_RATE_LEVEL_CONFIGURATION', 'ROLE_VIEW_HEART_RATE_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: 'hr/:action/:id',
        canActivate: [AuthGuard, PermissionGuard],
        component: HrComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_HEART_RATE_LEVEL_CONFIGURATION', 'ROLE_UPDATE_HEART_RATE_LEVEL_CONFIGURATION', 'ROLE_VIEW_HEART_RATE_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: "st",
        redirectTo: "st/add",
        pathMatch: 'full'
      }, {
        path: 'st/:action',
        canActivate: [AuthGuard, PermissionGuard],
        component: SkinTempComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_SKIN_TEMPERATURE_LEVEL_CONFIGURATION', 'ROLE_UPDATE_SKIN_TEMPERATURE_LEVEL_CONFIGURATION', 'ROLE_VIEW_SKIN_TEMPERATURE_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: 'st/:action/:id',
        canActivate: [AuthGuard, PermissionGuard],
        component: SkinTempComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_SKIN_TEMPERATURE_LEVEL_CONFIGURATION', 'ROLE_UPDATE_SKIN_TEMPERATURE_LEVEL_CONFIGURATION', 'ROLE_VIEW_SKIN_TEMPERATURE_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: "fall",
        redirectTo: "fall/add",
        pathMatch: 'full'
      }, {
        path: 'fall/:action',
        canActivate: [AuthGuard, PermissionGuard],
        component: FallComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_FALL_AND_IMMOBILITY_CONFIGURATION', 'ROLE_UPDATE_FALL_AND_IMMOBILITY_CONFIGURATION', 'ROLE_VIEW_FALL_AND_IMMOBILITY_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: 'fall/:action/:id',
        canActivate: [AuthGuard, PermissionGuard],
        component: FallComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_FALL_AND_IMMOBILITY_CONFIGURATION', 'ROLE_UPDATE_FALL_AND_IMMOBILITY_CONFIGURATION', 'ROLE_VIEW_FALL_AND_IMMOBILITY_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: "battery",
        redirectTo: "battery/add",
        pathMatch: 'full'
      }, {
        path: 'battery/:action',
        canActivate: [AuthGuard, PermissionGuard],
        component: BatteryComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_BATTERY_LEVEL_CONFIGURATION', 'ROLE_UPDATE_BATTERY_LEVEL_CONFIGURATION', 'ROLE_VIEW_BATTERY_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }, {
        path: 'battery/:action/:id',
        canActivate: [AuthGuard, PermissionGuard],
        component: BatteryComponent,
        data: {
          Permission: {
            Only: ['ROLE_CREATE_BATTERY_LEVEL_CONFIGURATION', 'ROLE_UPDATE_BATTERY_LEVEL_CONFIGURATION', 'ROLE_VIEW_BATTERY_LEVEL_CONFIGURATION'],
            RedirectTo: 'login'
          } as IPermissionGuardModel
        },
        children: []
      }
];

export const DeviceProfileConfigRouter:ModuleWithProviders  = RouterModule.forChild(routes);

@NgModule({
    imports:[
      CommonModule,
      Common_Module,
      ReactiveFormsModule,
      FormsModule,
      BrowserModule,
      BrowserAnimationsModule,
      MatButtonModule, MatCheckboxModule, MatRadioModule, MatAutocompleteModule, MatInputModule,
    MatDialogModule, MatSidenavModule, MatSelectModule, MatDialogModule, MatStepperModule, MatTooltipModule, MatSlideToggleModule,
      RouterModule.forChild(routes)      
    ],
    declarations:[
      LoraComponent,
      HrComponent,
      BatteryComponent,       
      FallComponent,
      FallComponent,
      SkinTempComponent,

    ]
})

export class DeviceProfileConfigurationModule{}

标签: angularnpmangular6angular7

解决方案


推荐阅读