简体   繁体   中英

Error: After Updating Angular Material Module

I have taken MOOC(Coursera Angular) and following it. Recently i have updated my npm since then am getting build errors. I have searched around the web but none of it solves my issue.

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'.

These are the errors am getting

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

If i remove the above line my code works fine but i need to continue with Angular Material as the course is based on this. A clear solution is appreciated as am not much familar with NPM packages. Thanks

My Package.JSON file

    {
  "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"
  }
}

It isn't working, because you need to import the specific material modules you want to use. Easiest thing to do is consolidate them into one shared Material module like the following:

Then in your root module app.module.ts import your shared material module

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 { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM