Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: $color: "var(--bs-primary-rgb)" is not a color for `rgba' in v5.1.0 #34693

Closed
harnishdesign opened this issue Aug 5, 2021 · 46 comments
Closed

Comments

@harnishdesign
Copy link

I try to compile in latest v5.1.0 So, I get error as below. have i wrong anything?

Error: $color: "var(--bs-primary-rgb)" is not a color for `rgba'
on line 41 of C:/xampp/htdocs/myproject/sass/bootstrap/_functions.scss
from line 2 of C:\xampp\htdocs\myproject\sass\stylesheet.scss

My stylesheet.scss

@import "bootstrap/functions";
@import "bootstrap/variables";
@import "bootstrap/mixins";
@import "bootstrap/vendor/rfs";

// Initialize
@import "variables";
@import "mixins";

// Core CSS
@import "reset";
@import "helpers";
@import "layouts";

// Content Blocks
@import "elements";
@import "social-icons";
@import "extras";
@diyadin2
Copy link

diyadin2 commented Aug 5, 2021

i have the same problem

@morrow95
Copy link

morrow95 commented Aug 5, 2021

Same here

@mdo
Copy link
Member

mdo commented Aug 5, 2021

Can you provide a reduced test case here? We use these RGB values to form RGBA colors for greater customization. It's not immediately clear here from your report what function or context is failing.

@morrow95
Copy link

morrow95 commented Aug 5, 2021

Line 41 from _functions.scss is :

40 : @function rgba-css-var($identifier, $target) {
41 :  @return rgba(var(--#{$variable-prefix}#{$identifier}-rgb), var(--#{$variable-prefix}#{$target}-opacity));
42 : }

The original poster is doing the same thing as I am. Importing the following in a custom scss file :

@import "bootstrap-5.1.0/scss/functions";
@import "bootstrap-5.1.0/scss/variables";
@import "bootstrap-5.1.0/scss/mixins";

so the variables, mixins, etc can be used in that file. No issues with prior versions... only started happening when I tried BS 5.1.0.

@mdo
Copy link
Member

mdo commented Aug 5, 2021

I'm not seeing issues on my end when compiling bootstrap.scss with only those three imports, or in the bootstrap-npm-starter project when importing those into a custom stylesheet.

Anyone have a reduced test case to show the problem?

@diyadin2
Copy link

diyadin2 commented Aug 5, 2021

Error while compiling scss file with Koala program.

@diyadin2
Copy link

diyadin2 commented Aug 5, 2021

1

@ffoodd
Copy link
Member

ffoodd commented Aug 5, 2021

@mdo Could be some compilers compatibility issue again, regarding rgba() that could be both a Sass function and a CSS function.

Sass (Ruby but maybe Libsass too) would throw an error since it needs a color value.

@MaxxDelusional
Copy link

MaxxDelusional commented Aug 5, 2021

My sass is compiling, but I get an error in the Edge dev tools, and the css class is not working.

Invalid Property Value:
background-color: get-function(rgba-css-var)("primary", "bg") !important

image

@mdo
Copy link
Member

mdo commented Aug 5, 2021

@ffoodd Definitely seems that way. Dart Sass working without issue in our repo and the npm starter kit.

@MaxxDelusional Looks like that's not compiling correctly then. What version of Sass are you using?

@morrow95
Copy link

morrow95 commented Aug 5, 2021

@diyadin2 Using Koala here as well.

@harnishdesign
Copy link
Author

@mdo I am also using Koala and get error.

@MaxxDelusional
Copy link

MaxxDelusional commented Aug 6, 2021

@mdo I am using the Web Compiler extension for Visual Studio. I am not entirely sure what compiler it uses behind the scenes.

https://github.com/madskristensen/WebCompiler

@morrow95
Copy link

morrow95 commented Aug 6, 2021

For what it's worth, those of us using Koala already know that it hasn't been updated/supported in years now, but it looks like quite a lot of others haven't been updated either from the responses coming in. Nothing wrong with the code being used just that a lot of us have compilers that can't handle it yet or are using ones like Koala that will never be updated.

Sidenote... someone should really come out with a Koala-like app for Windows as a replacement. I would gladly pay for something with the same features/usability - haven't found anything close to it which is why I still use it.

@harnishdesign
Copy link
Author

@morrow95 Yes, You are right. Koala hasn't been updated/supported.

@diyadin2 I am trying with Scout-app and, It is working fine now.

@morrow95
Copy link

morrow95 commented Aug 9, 2021

Is there any workaround for the time being while I try to find a replacement compiler? I'd prefer not to mod bs's scss files directly, but will do so in the meantime.

@harms-tbd
Copy link

@mdo I am using the Web Compiler extension for Visual Studio. I am not entirely sure what compiler it uses behind the scenes.

https://github.com/madskristensen/WebCompiler

I am using the same compiler and experiencing the same issue.

@mdo
Copy link
Member

mdo commented Aug 9, 2021

Oh boy, that compiler hasn't been updated in 6 years... I'd really suggest finding something else. I don't think we can practically provide support for something that is so far behind our development stack :\ .

@cklenk
Copy link

cklenk commented Aug 9, 2021

@mdo I am using the Web Compiler extension for Visual Studio. I am not entirely sure what compiler it uses behind the scenes.
https://github.com/madskristensen/WebCompiler

I am using the same compiler and experiencing the same issue.

Same here

@betojaton
Copy link

I have solved it with Scout App. (¬‿¬)

@morrow95
Copy link

@betojaton Scout just doesn't cut it for me... no javascript, can't do input/output maps, and so on. Koala, when it was maintained, killed Scout in features. I'm actually looking to switch over to vs code, but trying to find a way to mimic what Koala did is proving a bit challenging since I've never used it before or know what is out there.

@icebits
Copy link

icebits commented Aug 10, 2021

For those using Web Compiler extension. The default node-sass v4.9.3 not able to compile BS v5.1.0 anymore. Please manually download latest node-sass (at least v5.0) using npm, then replace node-sass folder in C:\Users<your id>\AppData\Local\Temp\WebCompiler1.12.394\node_modules. You also need to upgrade/replace existing Web Compiler's node.exe (located outside of node_modules folder), you can find the file after install node.js x64 for windows. Must use x64 executable file.

@softwarea
Copy link

For all those using Visual Studio 2019 and Mad Kristensen's "Web Compiler" extension: yes, this extension is five years old. I uninstalled this extension and instead installed another extension called "Sass Compiler", which is from Mad Kristensen as well. Using this new extension, the errors with BS v5.1.0 went away.

@icebits
Copy link

icebits commented Sep 6, 2021

@softwarea Glad you had found the solution. Indeed it is from the same developer. Sass compiler is using libsass.dll, not sure about this library. I had cloned the Web Compiler source code and compile the vsix with latest node-sass to use on visual studio 2019. There is another developer already done the extension that work on visual studio 2022 x64. But since node-sass already deprecated, so not sure whether these two extensions will continue to work on BS in future.

@mdo
Copy link
Member

mdo commented Sep 6, 2021

Going to close this out as a compiler issue. I've added a mention of this to the v5.1.1 blog post (see draft at twbs/blog#234). Please continue to leave comments here for alternative compilers for folks. Thanks!

@mdo mdo closed this as completed Sep 6, 2021
@mdo mdo removed the awaiting-reply label Sep 6, 2021
@zybersup
Copy link

zybersup commented Sep 29, 2021

I have just faced this problem and quickly got to know the cause from this discussion. I would also love to use Koala so I tried finding a solution with Koala. Finally I got a solution using Dart Sass as a system sass in Koala. However there are some modification needed.

the following steps:

  1. Download the standalone Dart Sass from https://github.com/sass/dart-sass/releases/tag/1.42.1, then extract and put it in your computer anywhere you want.
  2. Go to Koala > Settings > Sass.
  3. See Advanced Settings.
  4. Check Use the System Sass compiler.
  5. Put the full path to Dart Sass compiler in the box below. (In my case, it is "C:\path\to\dart-sass\sass.bat".) Must not add any arguments after the file location because Koala will enclose all of this with double quote to support directory name with spaces.
  6. Modify the sass.bat to remove unsupported options which Koala will pass out (for its default Ruby Sass) and modify some options supported by Dart Sass. I put the following lines into sass.bat just before the real execution line.

!!! The BAT script here has error with space in scss file path. Please instead use the fixed one from here: oklai/koala#837 (comment)

set check_style=%arguments: nested=%
if not "%check_nested%"=="%arguments%" set style=expanded
set check_style=%arguments: expanded=%
if not "%check_style%"=="%arguments%" set style=expanded
set check_style=%arguments: compact=%
if not "%check_style%"=="%arguments%" set style=compressed
set check_style=%arguments: compressed=%
if not "%check_style%"=="%arguments%" set style=compressed

set sourcemap=
set check_sourcemap=%arguments:--sourcemap=%
if not "%check_sourcemap%"=="%arguments%" set sourcemap=--no-source-map

set arguments=%1 %2 %3 %4 --style=%style% %sourcemap%
  1. Then enjoy conveniences from Koala.

Remark: Dart Sass will support only 2 options, source mapping [yes/no] and output style [expanded/compressed].

@morrow95
Copy link

morrow95 commented Sep 29, 2021

I have just faced this problem and quickly got to know the cause from this discussion. I would also love to use Koala so I tried finding a solution with Koala. Finally I got a solution using Dart Sass as a system sass in Koala. However there are some modification needed.

the following steps:

  1. Download the standalone Dart Sass from https://github.com/sass/dart-sass/releases/tag/1.42.1, then extract and put it in your computer anywhere you want.
  2. Go to Koala > Settings > Sass.
  3. See Advanced Settings.
  4. Check Use the System Sass compiler.
  5. Put the full path to Dart Sass compiler in the box below. (In my case, it is "C:\path\to\dart-sass\sass.bat".)
  6. Modify the sass.bat to remove unsupported options which Koala will pass out (for its default Ruby Sass) and modify some options supported by Dart Sass. I put the following lines into sass.bat just before the real execution line.
set check_style=%arguments: nested=%
if not "%check_nested%"=="%arguments%" set style=expanded
set check_style=%arguments: expanded=%
if not "%check_style%"=="%arguments%" set style=expanded
set check_style=%arguments: compact=%
if not "%check_style%"=="%arguments%" set style=compressed
set check_style=%arguments: compressed=%
if not "%check_style%"=="%arguments%" set style=compressed

set sourcemap=
set check_sourcemap=%arguments:--sourcemap=%
if not "%check_sourcemap%"=="%arguments%" set sourcemap=--no-source-map

set arguments=%1 %2 %3 %4 --style=%style% %sourcemap%
  1. Then enjoy conveniences from Koala.

Remark: Dart Sass will support only 2 options, source mapping [yes/no] and output style [expanded/compressed].

@zybersup Just tried your suggestion for Dart with Koala... whenever I try to compile it errors on every file. For example :

C:\Users\Support\Documents\My Web Sites\BS5\example.com\_config\scss\bootstrap.scss

'Web' is not recognized as an internal or external command, operable program or batch file.  Web was unexpected at this time.

Any ideas? Does it not like the spaces in the file location or something? That is the only place I can think of that the word 'Web' is referenced.

@zybersup
Copy link

Replied at oklai/koala#837 (comment).

@riodelphino
Copy link

riodelphino commented May 18, 2022

I think the cause is in the version of 'sass' command.

I tested to compile bootstrap 5.0.0 and 5.1.3 on mac, then I got same issue.

I checked the version of 'sass' command installed by gem.
It seems to be too old. (v3.4.25)

So,
gem uninstall sass

Because I am a beginner, I thought "npm is better ?"
So,
npm install sass -g

Then, it works.

( I chose npm. but I guess just upgrading gem also works, right ? )

@dogooddesignco
Copy link

I'm using Prepros to compile which is using Dart Sass 1.52.1 and I'm using Bootstrap 5.2.0. I'm getting the error:
Undefined variable. } @else { @return rgba (var(--#${$prefix}...
on line 47, column 26 of node_modules/bootstrap/scss/_functions.scss

image

Is there a known issue with this version of Dart Sass and Bootstrap?

@morpolspc
Copy link

@dogooddesignco - Been using BS 5.2.0 since it came out and haven't had this issue, but I am using Koala with Dart using the info earlier in this thread (not sure if that is the difference or not).

@bellatrix988
Copy link

bellatrix988 commented Sep 1, 2022

@dogooddesignco I had similar issue with undefined variable for the same line. It turned out that in bootstrap 5.2 they replaced variable $variable-prefix with $prefix and it caused an issue for css package I'm using for.

The downgrading bootstrap to 5.1.3 helped me. It worth to try.

@mrelliot69
Copy link

having also this issue with bootstrap 5.2 using scssphp compiler
any idea on how to solve it?

@mahyaghadrdan
Copy link

6. sass.bat j

Thank you. I did it but I can't open my sass.bat. it's opened just for less than 1 second and it's closed again. What should I do?

@maheshbokkisam
Copy link

I am getting below error

Angular 14.2.0
Bootstrap 5.2.2

image

my custom.scss file as below
image

@felcksn
Copy link

felcksn commented Nov 15, 2022

@maheshbokkisam I get the exact same error after updating to angular 14

@cybercussion
Copy link

cybercussion commented Nov 16, 2022

Am I losing my mind or did they rename variables in a dot release?

I had to do a diff with my scss/_variables.scss and node_modules/bootstrap/scss/_variables.scss and fix all the changes using a external diff tool.

Like:

// Prefix for :root CSS variables

$variable-prefix:             bs- !default; // Deprecated in v5.2.0 for the shorter `$prefix`
$prefix:                      $variable-prefix !default;

@russcarver
Copy link

russcarver commented Nov 19, 2022

I am getting something similar in Angular 15.0.0 (with Angular Material 15.0.0).

My app's color theme is customizable by a configuration loaded at runtime. As such, I set the theme to be based on CSS4 variables - eg:

:root {
  --theme-primary-50: #EEF6F5;
  --theme-primary-100: #D4EAE7;
  --theme-primary-200: #B8DCD7;
  --theme-primary-300: #9CCDC7;
  --theme-primary-400: #86C3BB;
  --theme-primary-500: #71B8AF;
  --theme-primary-600: #69B1A8;
  --theme-primary-700: #5EA89F;
  --theme-primary-800: #54A096;
  --theme-primary-900: #429186;
  --theme-primary-A100: #E7FFFC;
  --theme-primary-A200: #B4FFF4;
  --theme-primary-A400: #81FFED;
  --theme-primary-A700: #68FFE9;
}

$primaryPalette: (
  50 : var(--theme-primary-50),
  100 : var(--theme-primary-100),
  200 : var(--theme-primary-200),
  300 : var(--theme-primary-300),
  400 : var(--theme-primary-400),
  500 : var(--theme-primary-500),
  600 : var(--theme-primary-600),
  700 : var(--theme-primary-700),
  800 : var(--theme-primary-800),
  900 : var(--theme-primary-900),
  A100 : var(--theme-primary-A100),
  A200 : var(--theme-primary-A200),
  A400 : var(--theme-primary-A400),
  A700 : var(--theme-primary-A700),
  contrast: (
    50: var(--color__text),
    100: var(--color__text),
    200: var(--color__text),
    300: var(--color__text),
    400: var(--color__text),
    500: var(--color__text--light),
    600: var(--color__text--light),
    700: var(--color__text--light),
    800: var(--color__text--light),
    900: var(--color__text--light),
    A100: var(--color__text),
    A200: var(--color__text--light),
    A400: var(--color__text--light),
    A700: var(--color__text--light),
  )
);

...

// Define the primary, accent and warn palettes
$default-primary-palette: mat.define-palette($primaryPalette);
$default-accent-palette: mat.define-palette($accentPalette);
$default-warn-palette: mat.define-palette($warnPalette);

// Create the Material theme object
$theme: mat.define-light-theme($default-primary-palette, $default-accent-palette, $default-warn-palette);

@include mat.all-component-themes($theme);

// Apply the theme to the user components
@include components-theme($theme);

I then alter those variables at runtime. This used to work just fine, but now, Angular Material complains (at compile time) with this:

HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: $color: var(--theme-primary-500) is not a color.
   ╷
16 │     track-color: color.adjust(mdc-theme-color.prop-value($color), $alpha: -0.75),
   │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 16:18  -palette-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 28:7   @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 176:5     @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 216:3     disable-mdc-fallback-declarations()
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 175:3     using-mdc-theme()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 26:3   color()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 53:7   @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 47:3   theme()
  node_modules/@angular/material/core/theming/_all-theme.scss 47:5            @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/core/theming/_all-theme.scss 44:3            all-component-themes()
  src/app/scss/theme/_theme.scss 146:1    

Based on other responses above, is it possible Angular Material has a bug where it is no longer supporting CSS4 variables in its themes?

@AdrianM
Copy link

AdrianM commented Dec 2, 2022

same here (css variables no longer allowed with Angular 15.0.0?)

@alicelebidev
Copy link

I am getting something similar in Angular 15.0.0 (with Angular Material 15.0.0).

My app's color theme is customizable by a configuration loaded at runtime. As such, I set the theme to be based on CSS4 variables - eg:

:root {
  --theme-primary-50: #EEF6F5;
  --theme-primary-100: #D4EAE7;
  --theme-primary-200: #B8DCD7;
  --theme-primary-300: #9CCDC7;
  --theme-primary-400: #86C3BB;
  --theme-primary-500: #71B8AF;
  --theme-primary-600: #69B1A8;
  --theme-primary-700: #5EA89F;
  --theme-primary-800: #54A096;
  --theme-primary-900: #429186;
  --theme-primary-A100: #E7FFFC;
  --theme-primary-A200: #B4FFF4;
  --theme-primary-A400: #81FFED;
  --theme-primary-A700: #68FFE9;
}

$primaryPalette: (
  50 : var(--theme-primary-50),
  100 : var(--theme-primary-100),
  200 : var(--theme-primary-200),
  300 : var(--theme-primary-300),
  400 : var(--theme-primary-400),
  500 : var(--theme-primary-500),
  600 : var(--theme-primary-600),
  700 : var(--theme-primary-700),
  800 : var(--theme-primary-800),
  900 : var(--theme-primary-900),
  A100 : var(--theme-primary-A100),
  A200 : var(--theme-primary-A200),
  A400 : var(--theme-primary-A400),
  A700 : var(--theme-primary-A700),
  contrast: (
    50: var(--color__text),
    100: var(--color__text),
    200: var(--color__text),
    300: var(--color__text),
    400: var(--color__text),
    500: var(--color__text--light),
    600: var(--color__text--light),
    700: var(--color__text--light),
    800: var(--color__text--light),
    900: var(--color__text--light),
    A100: var(--color__text),
    A200: var(--color__text--light),
    A400: var(--color__text--light),
    A700: var(--color__text--light),
  )
);

...

// Define the primary, accent and warn palettes
$default-primary-palette: mat.define-palette($primaryPalette);
$default-accent-palette: mat.define-palette($accentPalette);
$default-warn-palette: mat.define-palette($warnPalette);

// Create the Material theme object
$theme: mat.define-light-theme($default-primary-palette, $default-accent-palette, $default-warn-palette);

@include mat.all-component-themes($theme);

// Apply the theme to the user components
@include components-theme($theme);

I then alter those variables at runtime. This used to work just fine, but now, Angular Material complains (at compile time) with this:

HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: $color: var(--theme-primary-500) is not a color.
   ╷
16 │     track-color: color.adjust(mdc-theme-color.prop-value($color), $alpha: -0.75),
   │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 16:18  -palette-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 28:7   @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 176:5     @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 216:3     disable-mdc-fallback-declarations()
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 175:3     using-mdc-theme()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 26:3   color()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 53:7   @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 47:3   theme()
  node_modules/@angular/material/core/theming/_all-theme.scss 47:5            @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/core/theming/_all-theme.scss 44:3            all-component-themes()
  src/app/scss/theme/_theme.scss 146:1    

Based on other responses above, is it possible Angular Material has a bug where it is no longer supporting CSS4 variables in its themes?

I've also just encountered this issue with Angular v15.0.0
Have you found a solution?

@Petmun
Copy link

Petmun commented Dec 6, 2022

I do have the same problem. Have you found a solution?

@alicelebidev
Copy link

I do have the same problem. Have you found a solution?

I'm stuck with this issue at the moment. So annoying...

@cybercussion
Copy link

In my case node_modules/bootstrap/scss/_variables.scss had been updated. And I had my own scss/theme/_variables.scss now out of date with Bootstrap 5.2. I had to do a diff to bring in the recent 'minor' update to satisfy missing SCSS variables.

@bobliwang
Copy link

bobliwang commented Dec 10, 2022

Hi mate,

Based on the comments from Angular team before line 16, it seems they have difficulty in set the proper value of track-color.

Seems this file was modified by angular team for mdc, and it calls color.adjust function in .scss which requires a 'REAL' color instead of one relying on a css variable.
WARNING: it may affect a little style in progress bar. (but who cares :P )

The work round for Angular 15 is to replace line 16 with line 17 in _progress-bar-theme.scss from angular material source code.

Screenshot 2022-12-10 at 8 09 05 pm

Cheers

I am getting something similar in Angular 15.0.0 (with Angular Material 15.0.0).

My app's color theme is customizable by a configuration loaded at runtime. As such, I set the theme to be based on CSS4 variables - eg:

:root {
  --theme-primary-50: #EEF6F5;
  --theme-primary-100: #D4EAE7;
  --theme-primary-200: #B8DCD7;
  --theme-primary-300: #9CCDC7;
  --theme-primary-400: #86C3BB;
  --theme-primary-500: #71B8AF;
  --theme-primary-600: #69B1A8;
  --theme-primary-700: #5EA89F;
  --theme-primary-800: #54A096;
  --theme-primary-900: #429186;
  --theme-primary-A100: #E7FFFC;
  --theme-primary-A200: #B4FFF4;
  --theme-primary-A400: #81FFED;
  --theme-primary-A700: #68FFE9;
}

$primaryPalette: (
  50 : var(--theme-primary-50),
  100 : var(--theme-primary-100),
  200 : var(--theme-primary-200),
  300 : var(--theme-primary-300),
  400 : var(--theme-primary-400),
  500 : var(--theme-primary-500),
  600 : var(--theme-primary-600),
  700 : var(--theme-primary-700),
  800 : var(--theme-primary-800),
  900 : var(--theme-primary-900),
  A100 : var(--theme-primary-A100),
  A200 : var(--theme-primary-A200),
  A400 : var(--theme-primary-A400),
  A700 : var(--theme-primary-A700),
  contrast: (
    50: var(--color__text),
    100: var(--color__text),
    200: var(--color__text),
    300: var(--color__text),
    400: var(--color__text),
    500: var(--color__text--light),
    600: var(--color__text--light),
    700: var(--color__text--light),
    800: var(--color__text--light),
    900: var(--color__text--light),
    A100: var(--color__text),
    A200: var(--color__text--light),
    A400: var(--color__text--light),
    A700: var(--color__text--light),
  )
);

...

// Define the primary, accent and warn palettes
$default-primary-palette: mat.define-palette($primaryPalette);
$default-accent-palette: mat.define-palette($accentPalette);
$default-warn-palette: mat.define-palette($warnPalette);

// Create the Material theme object
$theme: mat.define-light-theme($default-primary-palette, $default-accent-palette, $default-warn-palette);

@include mat.all-component-themes($theme);

// Apply the theme to the user components
@include components-theme($theme);

I then alter those variables at runtime. This used to work just fine, but now, Angular Material complains (at compile time) with this:

HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: $color: var(--theme-primary-500) is not a color.
   ╷
16 │     track-color: color.adjust(mdc-theme-color.prop-value($color), $alpha: -0.75),
   │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 16:18  -palette-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 28:7   @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 176:5     @content
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 216:3     disable-mdc-fallback-declarations()
  node_modules/@angular/material/core/mdc-helpers/_mdc-helpers.scss 175:3     using-mdc-theme()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 26:3   color()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 53:7   @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/progress-bar/_progress-bar-theme.scss 47:3   theme()
  node_modules/@angular/material/core/theming/_all-theme.scss 47:5            @content
  node_modules/@angular/material/core/theming/_theming.scss 402:3             private-check-duplicate-theme-styles()
  node_modules/@angular/material/core/theming/_all-theme.scss 44:3            all-component-themes()
  src/app/scss/theme/_theme.scss 146:1    

Based on other responses above, is it possible Angular Material has a bug where it is no longer supporting CSS4 variables in its themes?

@bobliwang
Copy link

not that bad if we change it to: track-color: var(--theme-primary-300)

@b9chris
Copy link

b9chris commented Aug 8, 2023

I had this problem also, even after getting Visual Studio to compile the file. The issue comes down to the rgba() function sometimes being a SASS extension, not a CSS built-in - which was fine until CSS variables were introduced:

https://stackoverflow.com/a/76862918/176877

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests