bootstrap: Darken function "must be a color" error V4
Hello, I want to preface this by saying there is a ticket open on this error but only collaborators are allowed to comment on it. I just need to know if this is something that is currently in the works? or if someone can tell me if there is a work around for this or if it’s something that I’m doing wrong.
Currently I am importing my custom variables over the bootstrap.scss file like so:
// Variables
@import 'config/variables';
// Bootstrap
@import 'node_modules/bootstrap/scss/bootstrap';
This is my setup:
"bootstrap": "^4.0.0",
"laravel-mix": "^1.0"
Laravel Mix uses Webpack for those who don’t know and from the looks of it uses the latest. What I am seeing happening when trying to run yarn run dev I get a series of errors.
ERROR in ./node_modules/css-loader?{"url":true,"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader/lib?{"sourceMap":true,"ident":"postcss","plugins":[null]}!./node_modules/resolve-url-loader?{"sourceMap":true,"root":"/Users/me/project-com/SourceCode/node_modules"}!./node_modules/sass-loader/lib/loader.js?{"precision":8,"outputStyle":"expanded","sourceMap":true}!./assets/scss/app.scss
Module build failed:
$link-hover-color : darken($link-color, 15%);
^
Argument `$color` of `darken($color, $amount)` must be a color
Backtrace:
assets/scss/config/_variables.scss:86, in function `darken`
assets/scss/config/_variables.scss:86
in /Users/me/project-com/SourceCode/assets/scss/config/_variables.scss (line 86, column 21)
@ ./assets/scss/app.scss 4:14-254
@ multi ./assets/js/app.js ./assets/scss/app.scss
ERROR in ./assets/scss/app.scss
Module build failed: ModuleBuildError: Module build failed:
$link-hover-color : darken($link-color, 15%);
^
Argument `$color` of `darken($color, $amount)` must be a color
Backtrace:
assets/scss/config/_variables.scss:86, in function `darken`
assets/scss/config/_variables.scss:86
in /Users/me/project-com/SourceCode/assets/scss/config/_variables.scss (line 86, column 21)
at runLoaders (/Users/me/project-com/SourceCode/node_modules/webpack/lib/NormalModule.js:195:19)
at /Users/me/project-com/SourceCode/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /Users/me/project-com/SourceCode/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/Users/me/project-com/SourceCode/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at Object.asyncSassJobQueue.push [as callback] (/Users/me/project-com/SourceCode/node_modules/sass-loader/lib/loader.js:55:13)
at Object.<anonymous> (/Users/me/project-com/SourceCode/node_modules/async/dist/async.js:2257:31)
at Object.callback (/Users/me/project-com/SourceCode/node_modules/async/dist/async.js:958:16)
at options.error (/Users/me/project-com/SourceCode/node_modules/node-sass/lib/index.js:294:32)
@ ./assets/scss/app.scss
@ multi ./assets/js/app.js ./assets/scss/app.scss
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 42 (7 by maintainers)
@andrade1379, @alireza4050 I had the same problem and error. I solved it like this:
theme-color() is a function
The problem lies in your app.css judging by the error message, so you are passing something wrong in the darken function.
Either way, for implementation help, you should ask on StackOverflow or something.
@JmRy I don’t understand what you’re trying to accomplish by just quoting that page because if you follow those exact directions, but call functions within the
custom.scssfile, it throws an error. That’s the problem!@JmRy I can see how my last post could have been seen as someone just wanting to find a flaw in documentation just for the sake of it. That was not my intention. I found this post after pulling my hair out trying to understand why I was getting an error.
I know that for me, if there was documentation explaining that the
_functions.scssfile needs to come before the_variables.scssfile, I would have been all set.I know this may not be the ultimate solution but perhaps just for now, it should be mentioned in the docs. Then later… if someone finds a way to make the setup more intuitive, great!
What do you guys think?
Closing out since this should be long resolved.
People other than developers use Bootstrap.
@andrade1379 I use the latest V4. This is not a workaround. In my opinion it’s the solution.
The errors described in this post indicate that SASS compiles as a value of the functions _(theme-color, assert-ascending, etc…) encoded in the _functions.scss file.
So just place this file before the variables, as does the bootstrap.css file.
Look the last message in https://github.com/twbs/bootstrap/issues/23331
I found that the problem is not in bootstrap but in the way the task is set in my gulpfile.
You probably have one single sass file that includes the others, so:
@JmRy It may very well be a solution but in my opinion a temporary one. Reason I say that is in the official documentation it clearly does not state that functions.scss needs to be inserted before variables.scss.
You can read here: http://getbootstrap.com/docs/4.0/getting-started/webpack/
@andrade1379 Sincerely, it’s a shame that you did not read the page I quoted
Here is a new excerpt:
Hoping that the documentation can be improved moving forward to reduce these errors.
Same issue here.
It work until alpha 6 where in scss/_variables.scss:194:
After that it’s changed to:
As @SteamWind said fixing it introduces another error:
Any news? It seems that if I change the bootstrap $link-color in _variables.scss to a hardcoded color, it works but an other error occurs in the file, then an other… Like a file was missing but I tried to import different bootstrap files in different orders (before, after my customs…), the main bootstrap.scss, etc.
@XhmikosR I’ve gone ahead and created a repo for you to clone. I’ve also added a README to walk you through the steps to reproduce the errors. Would you like me to add the repos link here?
https://gitlab.com/TikaL13/BS4-Build-Error