ReactJR
ReactJR

Reputation: 33

Unable to compile due to '@angular/material'; error

When downloading the following project on Angular 10: https://stackblitz.com/edit/angular-material-table-json-realtime-stock-quote-api?embed=1&file=main.ts&view=preview

Unable to compile due to the following error:

ERROR in src/material-module.ts:47:8 - error TS2306: File '/Users/ed/tabletest/node_modules/@angular/material/index.d.ts' is not a module.

if I run ng add @angular/material

Skipping installation: Package already installed ? Choose a prebuilt theme name, or "custom" for a custom theme: Deep Purple/A mber [ Preview: https://material.angular.io?theme=deeppurple-amber ] ? Set up global Angular Material typography styles? Yes ? Set up browser animations for Angular Material? Yes UPDATE package.json (1318 bytes) ✔ Packages installed successfully. Could not read Angular module file: /src/undefined.ts

Material-module.ts

import {A11yModule} from '@angular/cdk/a11y';
import {DragDropModule} from '@angular/cdk/drag-drop';
import {PortalModule} from '@angular/cdk/portal';
import {ScrollingModule} from '@angular/cdk/scrolling';
import {CdkStepperModule} from '@angular/cdk/stepper';
import {CdkTableModule} from '@angular/cdk/table';
import {CdkTreeModule} from '@angular/cdk/tree';
import {NgModule} from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import {
  MatAutocompleteModule,
  MatBadgeModule,
  MatBottomSheetModule,
  MatButtonModule,
  MatButtonToggleModule,
  MatCardModule,
  MatCheckboxModule,
  MatChipsModule,
  MatDatepickerModule,
  MatDialogModule,
  MatDividerModule,
  MatExpansionModule,
  MatGridListModule,
  MatIconModule,
  MatInputModule,
  MatListModule,
  MatMenuModule,
  MatNativeDateModule,
  MatPaginatorModule,
  MatProgressBarModule,
  MatProgressSpinnerModule,
  MatRadioModule,
  MatRippleModule,
  MatSelectModule,
  MatSidenavModule,
  MatSliderModule,
  MatSlideToggleModule,
  MatSnackBarModule,
  MatSortModule,
  MatStepperModule,
  MatTableModule,
  MatTabsModule,
  MatToolbarModule,
  MatTooltipModule,
  MatTreeModule,
} **from '@angular/material';**   //<<LINE 47

@NgModule({
    imports: [HttpClientModule],
  exports: [
    A11yModule,
    CdkStepperModule,
    CdkTableModule,
    CdkTreeModule,
    DragDropModule,
    MatAutocompleteModule,
    MatBadgeModule,
    MatBottomSheetModule,
    MatButtonModule,
    MatButtonToggleModule,
    MatCardModule,
    MatCheckboxModule,
    MatChipsModule,
    MatStepperModule,
    MatDatepickerModule,
    MatDialogModule,
    MatDividerModule,
    MatExpansionModule,
    MatGridListModule,
    MatIconModule,
    MatInputModule,
    MatListModule,
    MatMenuModule,
    MatNativeDateModule,
    MatPaginatorModule,
    MatProgressBarModule,
    MatProgressSpinnerModule,
    MatRadioModule,
    MatRippleModule,
    MatSelectModule,
    MatSidenavModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSnackBarModule,
    MatSortModule,
    MatTableModule,
    MatTabsModule,
    MatToolbarModule,
    MatTooltipModule,
    MatTreeModule,
    PortalModule,
    ScrollingModule,
    HttpClientModule
  ]
})
export class DemoMaterialModule {}

/** Copyright 2019 Google Inc. All Rights Reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at http://angular.io/license */

ERROR in src/material-module.ts:47:8 - error TS2306: File '/Users/tabletest/node_modules/@angular/material/index.d.ts' is not a module.

47 } from '@angular/material';
          ~~~~~~~~~~~~~~~~~~~

coplied

Upvotes: 2

Views: 908

Answers (1)

pzaenger
pzaenger

Reputation: 11973

You need to import these modules separately:

import { MatSliderModule } from '@angular/material/slider';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTableModule } from '@angular/material/table';
import { MatTabsModule } from '@angular/material/tabs';
import { MatToolbarModule } from '@angular/material/toolbar';

And so on. Then, it should work fine.

If you check node_modules/@angular/material/index.d.ts you see an almost empty file but a comment. This file does not export any Angular Material module hence the error.

For example node_modules/@angular/material/toolbar/index.d.ts:

/**
 * Generated bundle index. Do not edit.
 */
export * from './public-api';

//# sourceMappingURL=index.d.ts.map

And then in node_modules/@angular/material/toolbar/public-api.d.ts you find the accordant module:

/**
 * @license
 * Copyright Google LLC All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */
export * from './toolbar-module';
export * from './toolbar';

Upvotes: 1

Related Questions