使用 Angular 材质定义自定义主题时出现 SassError

Posted

技术标签:

【中文标题】使用 Angular 材质定义自定义主题时出现 SassError【英文标题】:SassError when defining custom themes using Angular Materials 【发布时间】:2021-02-27 20:49:31 【问题描述】:

我正在尝试使用此处描述的指南为 Angular 材质创建自定义主题:https://material.angular.io/guide/theming#defining-a-custom-theme

但是在定义浅色主题的颜色时出现错误:代码如下:

@import '~@angular/material/theming';
// Plus imports for other components in your app.

// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat-core();

// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue. Available color palettes: https://material.io/design/color/
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);

// The warn palette is optional (defaults to red).
$candy-app-warn:    mat-palette($mat-red);

// Create the theme object. A theme consists of configurations for individual
// theming systems such as `color` or `typography`.
$candy-app-theme: mat-light-theme((
  color: (
    primary: $candy-app-primary,
    accent: $candy-app-accent,
    warn: $candy-app-warn,  
  )
));

// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme);

我得到的错误是这样的:

./src/styles.scss 中的错误 (./node_modules/css-loader/dist/cjs.js??ref--13-1!./node_modules/postcss-loader/src??embedded!./ node_modules/resolve-url-loader??ref--13-3!./node_modules/sass-loader/dist/cjs.js??ref--13-4!./src/styles.scss) 模块构建失败(来自 ./node_modules/sass-loader/dist/cjs.js): SassError:函数 mat-light-theme 缺少参数 $accent。 在 src/styles.scss 的第 17 行

$candy-app-theme: mat-light-theme(( ------------------^ 任何帮助将不胜感激。

【问题讨论】:

你解决了这个问题吗?您是否曾在任何时候降级节点 sass?我认为这就是我造成这种情况的原因 【参考方案1】:

尝试使用

npm rebuild node-sass

【讨论】:

以上是关于使用 Angular 材质定义自定义主题时出现 SassError的主要内容,如果未能解决你的问题,请参考以下文章

Angular 材质自定义组件主题

创建自定义角度材质主题时最好的方法是啥?

Angular - 材质:进度条自定义颜色?

Angular 材质 io 预定义主题颜色

在材质表 React 中定义表列时使用渲染时出现类型错误

Angular 材质自定义选项卡