J4GD33P 51NGH
J4GD33P 51NGH

Reputation: 670

Angular throwing Material errors after upgrading to version 9

I've updated the Angular project from v8 to v9 and followed all the required updates but running ng serve throws material errors. I've imported all material components individually instead of importing directly from @angular/material and included all these in separate file material.module.ts. This file is imported in app.module.ts but still Angular is not detecting any material components and throwing below errors:

enter image description here

Below are the dependencies:
enter image description here


Note: I've tried almost all available solutions and asking this question after no success.

Upvotes: 0

Views: 882

Answers (1)

Johnathan Le
Johnathan Le

Reputation: 713

The real problem with your project is included all these in separate file material.module.ts . From Angular 9+, you should explicitly declare which Material Modules are imported instead of creating one shared module. I have resolved a problem before by refactoring most of own modules. Step by step here is:

  1. Remove Shared Material Module
  2. Run to print out all own modules have problem
  3. Declare explicitly Material Module which it has associated with.
@NgModule({
   imports: [
      MatToolbarModule
   ]
})
export class OwnModule { }

I know it is very painful but we don't have any choice to upgrade Angular 9+.

Upvotes: 3

Related Questions