I'm trying to set up Angular with SCSS and Bootstrap. I'm getting the following error when I try to run ng serve
:
./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
Steps to reproduce:
- Create Angular app with
ng new <app name>
npm i bootstrap
- Update
angular.json
file. Add boostrap tostyles
property:[...,"node_modules/bootstrap/scss/bootstrap.scss"]
- Add
src/scss/Custom.scss
file and populate, as per https://getbootstrap.com/docs/5.0/customize/sass/ (see below) - Import
@import "./scss/Custom.scss";
tosrc/styles.scss
.
My app works fine when my src/scss/Custom.scss
file looks like this:
// 1. Include functions first (so you can manipulate colors, SVGs, calc, etc)
@import "../../node_modules/bootstrap/scss/functions";
// // 2. Include any default variable overrides here
// // 3. Include remainder of required Bootstrap stylesheets
@import "../../node_modules/bootstrap/scss/variables";
@import "../../node_modules/bootstrap/scss/mixins";
// // 4. Include any optional Bootstrap components as you like
// @import "../../node_modules/bootstrap/scss/grid"; // Uncommenting this line causes error
But uncommenting the last line will cause the above error.
Package.json dependencies include:
{
...
"@angular/core": "^15.0.0",
"bootstrap": "^5.2.3",
}