首页 > 解决方案 > @import '~@material/theme'; 在styles.css 中不起作用

问题描述

当我按照在线说明 https://material.angular.io/guide/theming时出现错误

./src/styles.scss 中的错误 (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--14 -3!./src/styles.scss) 模块构建失败:@import '~@material/theme'; ^ 找不到或无法读取要导入的文件:~@material/theme。在 D:\Practice\angular\styles.scss (第 1 行,第 1 列)

我不知道为什么它没有找到材料/主题或为什么无法导入,因为我可以在我的 node_modules 文件下看到@material/theme。

@import '~@material/theme';

// always include only once per project
@include mat-core();

// import our custom themes
@import 'my-theme.scss';
@import 'my-light-theme.scss';
@import 'my-dark-theme.scss';

.my-theme {
  @include angular-material-theme($my-theme);
}

// additional css classes
// you can hardcode one of them on the <body> tag 
// or switch dynamically during runtime with [class]
.my-light-theme {
  @include angular-material-theme($my-light-theme);
}

.my-dark-theme {
  @include angular-material-theme($my-dark-theme);
}

标签: angularangular-materialfrontendangular-material-theming

解决方案


导入路径不正确,应该是:

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

您可以在此处查看更多信息


推荐阅读