bootstrap: Webpack build fails with "SassError: Undefined variable" when updating 5.1.3 -> 5.2.0

Prerequisites

Describe the issue

When updating 5.1.3 -> 5.2.0 our webpack build fails with the following error:

error  in ./assets/scss/app.scss

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
    ╷
142 │       values: $utilities-border-colors
    │               ^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
  node_modules/bootstrap/scss/_utilities.scss 142:15  @import
  assets/scss/app.scss 14:9                           root stylesheet

That line just imports the utilities @import "~bootstrap/scss/utilities";

Reduced test cases

Don’t know how to provide a test case for this as we don`t even use that variable.

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

No response

What version of Bootstrap are you using?

5.2.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 20
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for reporting this issue @gndk. There is a new _map.scss in v5.2.0. Don’t have the details regarding your Webpack build but you probably just need to @import "~bootstrap/scss/maps"; (that’s where $utilities-border-colors is defined) before @import "~bootstrap/scss/utilities";.

@turkic-dev: It is important to load the modules in the exact same order as in node_modules/bootstrap/scss/bootstrap.scss Also, the following modules must be loaded

@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/maps";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/utilities";
@import "~bootstrap/scss/helpers";
@import "~bootstrap/scss/utilities/api";

@turkic-dev: It is important to load the modules in the exact same order as in node_modules/bootstrap/scss/bootstrap.scss Also, the following modules must be loaded

@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/maps";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/utilities";
@import "~bootstrap/scss/helpers";
@import "~bootstrap/scss/utilities/api";

The problem was that I did not import ‘scss/maps’, ‘scss/helpers’ and ‘scss/utilities/api’ files

So I understanded it wrong in this thread. But still adding the import @import “~bootstrap/scss/maps”; in node_modules/bootstrap/scss/_utilities.scss resolved the issue that was mentioned at the beginning. Anyway I got rid of bootstrap, I removed it in my project as it caused to much problems

@import “~bootstrap/scss/functions”; @import “~bootstrap/scss/variables”;

use of the ~ is bad practice. Unless you show as I always do, you will generate errors. Here is what I always use:

ex: @import “…/node_modules/bootstrap/scss/_variables.scss”;

I know there are little shortcuts available – but why?

@BearCooder You should not change anything in node_modules, ever. Add @import "~bootstrap/scss/maps"; to your own css instead.

I know I can just add the import @import "~bootstrap/scss/maps"; in node_modules/bootstrap/scss/_utilities.scss and then it works but this is annoying as I need to repeat it everytime I do a fresh install with npm i. Will this be fixed?

Thanks for the quick reply @julien-deramond ! That did the trick 👍. I only looked at the patch notes in the GitHub release, so I completely missed that. Will remember to check the migration page more in the future 🙂