Search code examples
vue.jswebpacksassbulmabuefy

SassError: argument `$color` of `darken($color, $amount)` must be a color


I am attempting to add a custom color map in Bulma, with the following SCSS code:

// Set your colors
$primary: #5B43CC;
$primary-invert: findColorInvert($primary);
$twitter: #4099FF;
$twitter-invert: findColorInvert($twitter);
$facebook: #4267B2;
$facebook-invert: findColorInvert($facebook);

$custom-colors: (
  "foo": (black, grey),
);

// Import Bulma's core
@import "~bulma/sass/utilities/_all";

// Links
$link: $primary;
$link-invert: $primary-invert;
$link-focus-border: $primary;

// Import Bulma and Buefy styles 
// this has been moved to App.vue because it must be at the end
@import "~bulma";
@import "~buefy/src/scss/buefy";

But I get the following error:

 ERROR  Failed to compile with 6 errors                                                                                                           1:26:26 AM

 error  in ./src/App.vue?vue&type=style&index=0&lang=scss&

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: argument `$color` of `darken($color, $amount)` must be a color
        on line 150 of node_modules/bulma/sass/elements/button.sass, in function `darken`
        from line 150 of node_modules/bulma/sass/elements/button.sass
        from line 4 of node_modules/bulma/sass/elements/_all.sass
        from line 5 of node_modules/bulma/bulma.sass
        from line 40 of src/assets/scss/main.scss
        from line 2 of /c/Users/Raj/Projects/testsite/src/App.vue
>>           background-color: darken($color-invert, 5%); }

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


 @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=scss& 4:14-416 14:3-18:5 15:22-424
 @ ./src/App.vue?vue&type=style&index=0&lang=scss&
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

However, if I comment out // $primary-invert: findColorInvert($primary); then the error goes away. Also, if the snippet under // set your colors is moved after @import "~bulma/sass/utilities/_all", then the error also goes away.

What am I doing wrong here?

Note, this is a follow-up to this previous post


Solution

  • So as I mentioned in the comments, when it comes to Sass compilation it's all about ordering (of imports and/or variable declarations). Now, since those color inversions are using a Bulma utility called findColorInvert, which resides within utilities/functions.sass, we can't probably import the utilities with the original order here.

    We could split them and insert our customs in between the functions and derived-variables:

    @import "~bulma/sass/utilities/initial-variables";
    @import "~bulma/sass/utilities/functions";
    
    // Set your colors
    $primary: #5B43CC;
    $primary-invert: findColorInvert($primary);
    $twitter: #4099FF;
    $twitter-invert: findColorInvert($twitter);
    $facebook: #4267B2;
    $facebook-invert: findColorInvert($facebook);
    
    // Links
    $link: $primary;
    $link-invert: $primary-invert;
    $link-focus-border: $primary;
    
    $custom-colors: (
      "foo": (black, grey),
    );
    
    @import "~bulma/sass/utilities/derived-variables";
    @import "~bulma/sass/utilities/animations";
    @import "~bulma/sass/utilities/mixins";
    @import "~bulma/sass/utilities/controls";