Angular 4 + Material 2 SASS compile error “File to import not found or unreadable”

你离开我真会死。 提交于 2019-12-04 05:02:52

Put this in your .angular-cli.json:

"stylePreprocessorOptions": {
    "includePaths": [
        "../node_modules"
    ]
},

I solve preceding issue like following.

First step:
Create customTheme.scss in src directory.

@import '../node_modules/@angular/material/_theming';

@include mat-core();

$candy-app-primary: mat-palette($mat-cyan);
$candy-app-accent:  mat-palette($mat-green, A200, A100, A400);
$candy-app-warn:    mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
@include angular-material-theme($candy-app-theme);

Important: import statement depends to angular material version and also import statement location depends to your customTheme.scss location.


Second step:
Add customTheme.scss to styles array in .angular-cli.json

styles": [
        "styles.css",
        "customTheme.scss"
      ],

In material version 2.0.0-beta.3 there is no file '~@angular/material/theming';

If you check the node_modules/@angular/material directory you will see there is _theming.scss so you need to do:

@import '~@angular/material/_theming';

IMPORTANT:

There is a bug in the sass-loader v6.0.4 you need to add .scss extension to your import@import '~@angular/material/_theming.scss'; with the next sass-loader v6.0.5 coming .scss no longer needed

Replace @import '~@angular/material/core/theming/all-theme'; With @import "~@angular/material/_theming.scss";

also, use a mat-core instead of md-core.

@include mat-core();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!