Bootstrap SCSS: $color: theme-color("primary") is not a color
Asked Answered
F

4

12

I'm trying to override bootstrap4 styles. I have no experience with Sass, but this looks like an error in the bootstrap SCSS file.

My custom file is:

/* custom.scss */    
/* -------begin customization-------- */  
$body-bg: #000;
$body-color: #111;
/* -------end customization-------- */  

/* import the necessary Bootstrap files */
@import "/bootstrap-4.0.0/scss/_variables.scss";

I'm using bootstrap 4.4.1, but could only find a scss file for 4.0.0.

On

sass /custom.scss /custom.css 

I get:

 $color: theme-color("primary") is not a color.
    ╷
152 │ $link-hover-color:          darken($link-color, 15%) !default;
    │                             ^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
  /bootstrap-4.0.0/scss/_variables.scss 152:29  @import
  /custom.scss 8:9                   root stylesheet

The target custom.css file contains:

> /* Error: $color: theme-color("primary") is not a color.  *     ,  *
> 152 | $link-hover-color:          darken($link-color, 15%) !default; 
> *     |                             ^^^^^^^^^^^^^^^^^^^^^^^^  *     '  *   /scss/_variables.scss 152:29  @import  *   custom.scss 8:9                 root stylesheet */
> 
> body::before {   font-family: "Source Code Pro", "SF Mono", Monaco,
> Inconsolata, "Fira Mono",
>       "Droid Sans Mono", monospace, monospace;   white-space: pre;   display: block;   padding: 1em;   margin-bottom: 1em;   border-bottom:
> 2px solid black;   content: 'Error: $color: theme-color("primary") is
> not a color.\a     \2577 \a 152 \2502  $link-hover-color:         
> darken($link-color, 15%) !default;\a     \2502                        
> ^^^^^^^^^^^^^^^^^^^^^^^^\a     \2575 \a   /scss/_variables.scss 152:29
> @import\a   \/custom.scss 8:9                   root stylesheet'; }

Any insights?

Fechter answered 27/4, 2020 at 18:37 Comment(1)
The same Issue I am facing in bootstrap v5.3.3 and none of the below-suggested answer working for meAyer
R
13

The problem is the order in which you have imported the files. Please try this way and see if it works

  1. First import the bootstrap functions and variables
/* === Import Bootstrap functions and variables === */
@import "/bootstrap/scss/functions";
@import "/bootstrap/scss/variables";
  1. Import you custom variable file in which you have overrided the bootstrap theme-colors and other bootstrap variables.
/* === Import Custom variables === */
@import '/variables';
  1. Finally, the bootstrap main scss: So that new one is created based on your theme variables ( 2nd step ) and is applied throughout the application
/* === Boostrap Main SCSS === */
@import "/bootstrap/scss/bootstrap";
Rolandrolanda answered 16/5, 2020 at 5:45 Comment(0)
W
4

theme-color is an internal function of bootstrap:

 $color: theme-color("primary") is not a color.

Import bootstrap functions before import variables. Something like this:

@import "/bootstrap-4.0.0/scss/functions";
@import "/bootstrap-4.0.0/scss/variables";
Waitabit answered 16/5, 2020 at 4:27 Comment(0)
C
2

If you are using bootstrap 5, you can just replace it with variable $primary

Carrot answered 11/2, 2023 at 11:58 Comment(0)
K
0

Variable import must come after the bootstrap functions import..

@import "../../../node_modules/bootstrap/scss/functions";
@import "bootstrap-variables";
Karlik answered 11/1, 2023 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.