错误:更新角度材质模块后

时间:2018-03-13 19:04:12

标签: angular angular-material

我已经参加了MOOC(Coursera Angular)并跟随它。最近我更新了我的npm,从那时起我的构建错误。我在网上搜索过但没有一个能解决我的问题。

ERROR in node_modules/@angular/material/dialog/typings/dialog-container.d.ts(10,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'BasePortalOutlet'.
 node_modules/@angular/material/dialog/typings/dialog-container.d.ts(10,45): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'CdkPortalOutlet'.
node_modules/@angular/material/expansion/typings/accordion.d.ts(1,30): error TS2307: Cannot find module '@angular/cdk/accordion'.
node_modules/@angular/material/expansion/typings/expansion-panel.d.ts(10,34): error TS2307: Cannot find module '@angular/cdk/accordion'.
node_modules/@angular/material/expansion/typings/expansion-panel.d.ts(36,14): error TS2314: Generic type 'TemplatePortal<C>' requires 1 type argument(s).
node_modules/@angular/material/select/typings/select.d.ts(11,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/overlay"' has no exported member 'CdkConnectedOverlay'.
node_modules/@angular/material/sidenav/typings/drawer.d.ts(15,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/scrolling"' has no exported member 'CdkScrollable'.
node_modules/@angular/material/snack-bar/typings/snack-bar-container.d.ts(10,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'BasePortalOutlet'.
node_modules/@angular/material/snack-bar/typings/snack-bar-container.d.ts(10,45): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'CdkPortalOutlet'.
node_modules/@angular/material/tabs/typings/tab-body.d.ts(10,26): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'CdkPortalOutlet'.
node_modules/@angular/material/tabs/typings/tab-body.d.ts(62,15): error TS2314: Generic type 'TemplatePortal<C>' requires 1 type argument(s).
node_modules/@angular/material/tabs/typings/tab-label.d.ts(9,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'CdkPortal'.
 node_modules/@angular/material/tabs/typings/tab.d.ts(28,23): error TS2314: Generic type 'TemplatePortal<C>' requires 1 type argument(s).
src/app/app.module.ts(4,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/material/material"' has no exported member 'MaterialModule'.

这些是我得到的错误

import { MaterialModule } from '@angular/material';

如果我删除上面的行我的代码工作正常,但我需要继续使用Angular Material,因为课程是基于此。一个明确的解决方案是值得赞赏的,因为我对NPM软件包不太熟悉。感谢

我的Package.JSON文件

    {
  "name": "con-fusion",
  "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"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.8",
    "@angular/cdk": "^2.0.0-beta.12",
    "@angular/common": "^5.2.8",
    "@angular/compiler": "^5.2.8",
    "@angular/core": "^5.2.8",
    "@angular/flex-layout": "^5.0.0-beta.13",
    "@angular/forms": "^5.2.8",
    "@angular/http": "^5.2.8",
    "@angular/material": "^5.2.4",
    "@angular/platform-browser": "^5.2.8",
    "@angular/platform-browser-dynamic": "^5.2.8",
    "@angular/router": "^5.2.8",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.5.7",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.7.3",
    "@angular/compiler-cli": "^5.2.8",
    "@angular/language-service": "^5.2.8",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.102",
    "codelyzer": "^4.2.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.4.2",
    "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"
  }
}

1 个答案:

答案 0 :(得分:4)

它不起作用,因为您需要导入要使用的特定材料模块。最简单的方法是将它们合并到一个共享的Material模块中,如下所示:

然后在您的根模块app.module.ts中导入您的共享材料模块

import{ MaterialModule } from ' ./material.module.ts';

<强> material.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
    MatAutocompleteModule,
    MatButtonModule,
    MatButtonToggleModule,
    MatCardModule,
    MatCheckboxModule,
    MatChipsModule,
    MatDatepickerModule,
    MatDialogModule,
    MatExpansionModule,
    MatFormFieldModule,
    MatGridListModule,
    MatIconModule,
    MatInputModule,
    MatListModule,
    MatMenuModule,
    MatNativeDateModule,
    MatPaginatorModule,
    MatProgressBarModule,
    MatProgressSpinnerModule,
    MatRadioModule,
    MatRippleModule,
    MatSelectModule,
    MatSidenavModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSnackBarModule,
    MatSortModule,
    MatTableModule,
    MatTabsModule,
    MatToolbarModule,
    MatTooltipModule,
    MatStepperModule,
  } from '@angular/material';

@NgModule({
  imports: [
    MatAutocompleteModule,
    MatButtonModule,
    MatButtonToggleModule,
    MatCardModule,
    MatCheckboxModule,
    MatChipsModule,
    MatStepperModule,
    MatDatepickerModule,
    MatDialogModule,
    MatExpansionModule,
    MatFormFieldModule,
    MatGridListModule,
    MatIconModule,
    MatInputModule,
    MatListModule,
    MatMenuModule,
    MatNativeDateModule,
    MatPaginatorModule,
    MatProgressBarModule,
    MatProgressSpinnerModule,
    MatRadioModule,
    MatRippleModule,
    MatSelectModule,
    MatSidenavModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSnackBarModule,
    MatSortModule,
    MatTableModule,
    MatTabsModule,
    MatToolbarModule,
    MatTooltipModule,
  ],
  exports: [
    MatAutocompleteModule,
    MatButtonModule,
    MatButtonToggleModule,
    MatCardModule,
    MatCheckboxModule,
    MatChipsModule,
    MatStepperModule,
    MatDatepickerModule,
    MatDialogModule,
    MatExpansionModule,
    MatFormFieldModule,
    MatGridListModule,
    MatIconModule,
    MatInputModule,
    MatListModule,
    MatMenuModule,
    MatNativeDateModule,
    MatPaginatorModule,
    MatProgressBarModule,
    MatProgressSpinnerModule,
    MatRadioModule,
    MatRippleModule,
    MatSelectModule,
    MatSidenavModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSnackBarModule,
    MatSortModule,
    MatTableModule,
    MatTabsModule,
    MatToolbarModule,
    MatTooltipModule,
  ],
})
export class MaterialModule { }