Having some trouble setting up Angular with SCSS and Bootstrap. When attempting to run ng serve
, I encountered the following error:
./src/styles.scss - Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
114 │ @each $key, $value in $gutters {
│ ^^^^^^^^
╵
node_modules/bootstrap/scss/mixins/_grid.scss 114:29 @content
node_modules/bootstrap/scss/mixins/_breakpoints.scss 68:5 media-breakpoint-up()
node_modules/bootstrap/scss/mixins/_grid.scss 72:5 make-grid-columns()
node_modules/bootstrap/scss/_grid.scss 32:3 @import
src/scss/Custom.scss 11:9 @import
src/styles.scss 2:9 root stylesheet
To replicate this issue, follow these steps:
- Create an Angular app using
ng new <app name>
npm i bootstrap
- Edit the
angular.json
file and add Bootstrap to thestyles
property:[...,"node_modules/bootstrap/scss/bootstrap.scss"]
- Add a
src/scss/Custom.scss
file and set it up as described at https://getbootstrap.com/docs/5.0/customize/sass/ (details below) - Import
into@import "./scss/Custom.scss";
src/styles.scss
.
Everything works fine when my src/scss/Custom.scss
file is structured like this:
// 1. Include functions first (for color manipulation, SVGs, calc, etc)
@import "../../node_modules/bootstrap/scss/functions";
// // 2. Include any default variable overrides here
// // 3. Include remaining required Bootstrap stylesheets
@import "../../node_modules/bootstrap/scss/variables";
@import "../../node_modules/bootstrap/scss/mixins";
// // 4. Include optional Bootstrap components as needed
// @import "../../node_modules/bootstrap/scss/grid"; // Uncommenting this line triggers error
However, uncommenting the last line leads to the mentioned error.
Dependencies listed in Package.json include:
{
...
"@angular/core": "^15.0.0",
"bootstrap": "^5.2.3",
}