Search code examples
angularsassangular-material

Can't find stylesheet to import. Angular 17


i'm trying to import angular material theming in the styles.scss file, But when i run ng serve, it throws the "Can't find stylesheet to import." Error.

Below is my import

@import '@angular/material/theming';

enter image description here I'm currently using Angular cli 17.

I've tried importing using the @use, but the error was the same. And i tried to change the path of the import to the node_module/@angular/material/theming.


Solution

  • Here is how I solved it. In your global stylesheet, like styles.scss:

    1. make sure you have @use '@angular/material' as mat;, and it is before all @include statements.
    2. remove @import '@angular/material/theming';
    3. Replace @include mat-core; with @include mat.core;
    4. If present, replace @include mat.all-legacy-component-themes($the-theme-you-use); with @include mat.all-component-themes($the-theme-you-use);

    Make sure that $the-theme-you-use exists.