9

I have custom theme pallet for my project which is working fine with version ^12.2.13 of the angular material but not with ^13.2.3. Below is my SCSS for custom theming:

custome-mat-theme.scss

@import '~@angular/material/theming';
@include mat-core();

$cust-blue: (primary: #002a5c, contrast: (primary: #ffffff));
$cust-gold: (accent: #989100, contrast: (accent: #ffffff));
$primary: mat-palette($cust-blue, primary);
$accent: mat-palette($cust-gold, accent);

$theme: mat-light-theme($primary, $accent);

@include angular-material-theme($theme);

angular.json

"styles": [
  "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
  "./node_modules/ngx-toastr/toastr.css",
  "src/styles.css",
  "src/assets/css/custom-mat-theme.scss"
]

Error

./src/assets/css/custom-mat-theme.scss.webpack[javascript/auto]!=!./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].rules[0].oneOf[0].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].rules[0].oneOf[0].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[6].rules[1].use[0]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[6].rules[1].use[1]!./src/assets/css/custom-mat-theme.scss

  • Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: 'Hue "100" does not exist in palette. Available hues are: primary, contrast' ╷ 55 │ lighter: _get-color-from-palette($base-palette, $lighter), │
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ╵
    node_modules@angular\material\core\theming_theming.scss 55:14
    define-palette()
    node_modules@angular\material\core\theming_theming-deprecated.scss 16:11 palette() src\assets\css\custom-mat-theme.scss 6:11
    root stylesheet

Can anyone tell me whats wrong with this?

Barefaced Bear
  • 688
  • 1
  • 9
  • 30
  • There were some changes in last versions and `@use` should be used instead of `@import` you can check the tutorial for theming [here](https://material.angular.io/guide/theming). More to `SCSS modules` [here](https://css-tricks.com/introducing-sass-modules/). Not sure if this helps. I will try to reproduce the error. – joka00 Feb 28 '22 at 15:57
  • I have tried using "@use" but that didn't help. Also tried looking into the official documentation but I've less knowledge about SCSS – Barefaced Bear Feb 28 '22 at 16:14
  • It seems that from v13 all palette hue values must be defined. Check this discussion https://github.com/angular/components/issues/24250 – Maksat Rahmanov Mar 01 '22 at 07:48
  • @MaksatRahmanov can you provide a sample on how to define all the hues in the palette as I don't require all the hues for my project? – Barefaced Bear Mar 01 '22 at 10:14
  • @BarefacedBear it will look like this https://github.com/angular-university/angular-material-course/blob/master/src/styles.scss – Maksat Rahmanov Mar 01 '22 at 10:27
  • @BarefacedBear could you solve the problem with provided sample? – Maksat Rahmanov Mar 02 '22 at 10:37

1 Answers1

7

It seems that material needs at least hue: 100, hue 500 and hue 700 (probably for functions like lighter etc).

I had the same problem as you, I only defined that hue 500. I then set hue 100 and hue 700 for each color and it solved my problem. Personally, for beginning, I used the same color for the three hue.

Dharman
  • 30,962
  • 25
  • 85
  • 135
RobinE
  • 79
  • 2