blueprint: Unable to compile BluePrint 4 SCSS with webpack sass-loader
Environment
- Package version(s): @blueprintjs/core: 4.17.8, sass: 1.60.0, sass-loader: 13.2.2, webpack: 5.73.0, node 16.16.0
- Operating System: Ubuntu 22.04
- Browser name and version: Chrome: 111.0.5563.110
Steps to reproduce
- Install @blueprintjs/core using npm:
npm install @blueprintjs/core@4.17.8 - Create an index.scss file that imports the blueprint scss file:
@import '@blueprintjs/core/src/blueprint';
- Add webpack configuration using sass-loader e.g.
module: {
rules: [
{
test: /\.(css|scss|sass)/,
use: [
{
loader: 'sass-loader',
},
],
}
},
Actual behavior
ERROR in ./style/index.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./style/index.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: (path: (fill: hsl(213.75, 10.8108108108%, 50%))) isn't a valid CSS value.
╷
39 │ background: svg-icon("16px/chevron-right.svg", (path: (fill: $pt-icon-color)));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ unknown function treated as plain CSS
╵
node_modules/@blueprintjs/core/src/components/breadcrumbs/_breadcrumbs.scss 39:54 @import
node_modules/@blueprintjs/core/src/components/_index.scss 5:9 @import
node_modules/@blueprintjs/core/src/blueprint.scss 18:9 @import
style/index.scss 5:9 root stylesheet
SassError: SassError: (path: (fill: hsl(213.75, 10.8108108108%, 50%))) isn't a valid CSS value.
╷
39 │ background: svg-icon("16px/chevron-right.svg", (path: (fill: $pt-icon-color)));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ unknown function treated as plain CSS
╵
node_modules/@blueprintjs/core/src/components/breadcrumbs/_breadcrumbs.scss 39:54 @import
node_modules/@blueprintjs/core/src/components/_index.scss 5:9 @import
node_modules/@blueprintjs/core/src/blueprint.scss 18:9 @import
style/index.scss 5:9 root stylesheet
at Object.loader (/home/adam/Documents/source/frontend/node_modules/sass-loader/dist/index.js:56:14)
@ ./style/index.scss 8:6-183 22:17-24 26:7-21 58:25-39 59:36-47 59:50-64 63:6-73:7 64:54-65 64:68-82 70:42-53 70:56-70 72:21-28 83:0-153 83:0-153 84:22-29 84:33-47 84:50-64 61:4-74:5
@ ./src/index.ts 4:0-29
Expected behavior
I would expect all of the blueprint internal SCSS files (e.g. the breadcrumb component scss file) to compile out of the box.
I have looked at all the similar issues raised but I am unable to follow them or to get this SCSS compiling. Are there any other steps that need to be done after installing this version of Blueprint? Previously working on Blueprint v3 had no compilation issues.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 20 (5 by maintainers)
Hi, wondering if there is any chance of an update on resolving this issue within the library? There are a number of things that make the source issue a pain, including:
Given it is a few functions, wondering if it would be possible to take another look?
Thanks
@eastside Thank you for the gist, I managed to make it work with Vite 4. There were 2 errors in your code which required adjustments:
"was missing at the end ofurl("...)in base64 caseAdditionally, it was required to install
postcss-scssand createpostcss.config.jsconfig file to support scss imports:That’s all I had to adjust
FYI @prachibansal01
Thanks all!
For anyone else who needs a workaround literally asap, I made a quick gist here: https://gist.github.com/eastside/adcdf0d189c7470be241a851c5add350
Instead of the normal factory, you’d use
legacySassSvgInlinerFactory. It works almost the same as the original factory, (except optimize doesn’t work), at least through the current version of Blueprint.js.You’d just make a new file, maybe call it
sassSvgInliner.mjs, and then of course import it:@adidahiya I got the above to start running by turning my webpack config into es6 format.
However, I get an error when running webpack with the sassSvgInliner is this something that has been seen before or could something be configured wrong?
When I add console logs to sassSvgInliner function, I get this output for the args paramter:
sass.types.String { dartValue: "16px/chevron-right.svg" }The sass in _breadcrumbs.scss is:
background: svg-icon("16px/chevron-right.svg", (path: (fill: $pt-icon-color)));and later on in the file
background: svg-icon("16px/chevron-right.svg", (path: (fill: $pt-dark-icon-color)));@ahaganDEV Yes, this is enforced by the “engines” constraint defined for the @blueprintjs/node-build-scripts package.
Sorry for the trouble here, could you share some of the issues you encountered with that approach? I’m open to making bugfixes which make it possible to continue compiling Blueprint’s Sass code when it’s consumed as an NPM package.
I don’t have a great alternative solution right now that doesn’t involve advanced Blueprint consumers storing a copy of the icons SVG folder. We inline icons in a few places across the code base and there’s a bit of work to untangle that which I don’t have the bandwidth to do right now. So the inlining has to stay, at least for now.
Note that the
svg-icon()function is only used for a few specific icons, so you really only need to ensure these files exist (I don’t have plans to add any more usage ofsvg-icon()to the code base):