question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Colors and theming] - Exception: "$color of red($color) must be a color" for certain colors

See original GitHub issue

When I’m trying to adjust the color theme sometimes I get an exception on SCSS compile-time:

ERROR in ./resources/sass/app.scss
Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: argument `$color` of `red($color)` must be a color
        on line 100 of node_modules/@react-md/theme/dist/_color-a11y.scss, in function `red`
        from line 100 of node_modules/@react-md/theme/dist/_color-a11y.scss, in function `rmd-theme-luminance`
        from line 118 of node_modules/@react-md/theme/dist/_color-a11y.scss, in function `rmd-theme-contrast`
        from line 138 of node_modules/@react-md/theme/dist/_color-a11y.scss, in function `rmd-theme-tone`
        from line 84 of node_modules/@react-md/chip/dist/_variables.scss, in function `if`
        from line 83 of node_modules/@react-md/chip/dist/_variables.scss
        from line 6 of node_modules/@react-md/chip/dist/_functions.scss
        from line 12 of node_modules/@react-md/chip/dist/_mixins.scss
        from line 7 of node_modules/react-md/dist/_react-md.scss
        from line 6 of XXX\resources\sass\app.scss
>> ed: nth($rmd-theme-linear-channel-values, red($color) + 1);

   ------------------------------------------^

    at XXX\node_modules\webpack\lib\NormalModule.js:316:20
    at XXX\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at XXX\node_modules\loader-runner\lib\LoaderRunner.js:233:18
    at context.callback (XXX\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at Object.callback (XXX\node_modules\sass-loader\dist\index.js:73:7)
    at Object.done [as callback] (XXX\node_modules\neo-async\async.js:8069:18)
    at options.error (XXX\node_modules\node-sass\lib\index.js:294:32)
 @ ./resources/sass/app.scss

This happens with some colors. deep-purple works for example

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mlaursencommented, Jul 21, 2020

I believe 353de23 should have fixed this issue and is released in v2.1.1. The simple test script I wrote to compile all $rmd-* colors worked without throwing errors with this fix, but just let me know if this error still occurs and I’ll reopen this issue.

Simple test script (mostly so I can reference this again)
const { renderSync } = require('node-sass');
const scssVariables = require('@react-md/theme/dist/scssVariables').default;

const colors = Object.keys(scssVariables).filter(
  (name) => !name.startsWith('rmd-theme')
);

const errors = [];
colors.forEach((color) => {
  const data = `@import '@react-md/theme/dist/scss/color-palette';

$rmd-theme-primary: $${color};

@import 'react-md/dist/scss/react-md';
@include react-md-utils;
`;

  try {
    // console.log(`Trying to compile '$${color}'...`);
    // console.log(data);
    // console.log('');
    renderSync({
      data,
      includePaths: ['node_modules'],
    });
    // console.log('Compiled successfully!');
  } catch (error) {
    errors.push({ color, error });
  }
});

console.log(JSON.stringify(errors, null, 2));
0reactions
mlaursencommented, Jul 21, 2022

I can try to help out if you provide the following information:

  • version of react-md and sass
  • a stack trace of the error
  • what $rmd-* overrides you are using
  • what build tool (create-react-app, nextjs, gatsby, vite, etc) - optional
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap SCSS: $color: theme-color("primary") is not a color
I'm trying to override bootstrap4 styles. I have no experience with Sass, but this looks like an error in the bootstrap SCSS file....
Read more >
Theme Color | Visual Studio Code Extension API
Theme Color reference that lists all themable colors in Visual Studio Code. ... Some colors should not be opaque in order to not...
Read more >
Building a Material Theme on Android: Color
How to create a color theme on Android using the MDC library. ... Some, such as colorSurface , use neutral colors so relying...
Read more >
Color - Foundations - Human Interface Guidelines - Design
Consider how the colors you use might be perceived in other countries and cultures. For example, red communicates danger in some cultures, but...
Read more >
Color | Android Developers
Color ints are the most common representation of colors on Android and have been ... The red, green and blue components must be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found