Question
How can I add bootstrap and react-bootstrap to my custom SPFX Webpart?
Steps I have taken
- Add bootstrap, react-bootstrap and @types/bootstrap
- Overwrite defaulf bootstrap variables with my scss file
- Import scss file into my application
What is the problem?
Currently the custom webpart is not building and exits with an error I can't do nothing with. There is no semicolon missing.
This line is causing the error: @import "~bootstrap/scss/bootstrap"
Because I would like to overwrite certain default sass bootstrap variables I have to load bootstrap second. With Sharepoint's spcomponentloader this is not really possible.
Bootstrap css loads fine with the following code, however my variables are not taken into consideration cause there are loaded on second place.
SPComponentLoader.loadCss("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css");
Error
exited with code 2
Error - [webpack] 'dist':
./lib/webparts/webpartDgdmHelloworld/components/Theme.module.css (./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/src??postcss!./lib/webparts/webpartDgdmHelloworld/components/Theme.module.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
SyntaxError
(40:4) Missed semicolon
@ ./lib/webparts/webpartDgdmHelloworld/components/Theme.module.css 1:14-155
@ ./lib/webparts/webpartDgdmHelloworld/components/Theme.module.scss.js
@ ./lib/webparts/webpartDgdmHelloworld/components/WebpartDgdmHelloworld.js
@ ./lib/webparts/webpartDgdmHelloworld/WebpartDgdmHelloworldWebPart.js
Same happens when trying to use react-bootstrap in my SPFX webpart. The following occurs when importing it:
Error - [tsc] node_modules/@popperjs/core/lib/createPopper.d.ts(1,73): error TS1005: ';' expected.
Error - [tsc] node_modules/@popperjs/core/lib/modifiers/applyStyles.d.ts(1,13): error TS1005: '=' expected.