-
-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exporting variables from SCSS file to JavaScript no longer works in css-loader 4.x.x #1179
Comments
https://github.com/webpack-contrib/css-loader#compiletype, we even have example in docs for this case https://github.com/webpack-contrib/css-loader#separating-interoperable-css-only-and-css-module-features |
Why is this issue closed? Where is the solution? I have the same problem and I can't find any solution. |
See the linked CRA 4 issue. Basically you change your css-loader options in webpack for SCSS files so the
|
I had similar issue with packages: and configuration: After upgrading style-loader from 2.0.0 to 3.2.1 SCSS variables imported in JS stops working - empty object: ` export const REPORT_STATUS = { const REPORT_STATUS_TO_COLOR_MAP = { |
I ran into (what I think is) this issue today and this thread seems to rank quite high for it so here's what ended up being my solution: make sure your JS import uses the I had to change: const { tabletPx } = require('../../scss/_variables.scss'); To: const { tabletPx } = require('../../scss/_variables.scss').default; The config for recent versions of // ...
{
loader: 'css-loader',
options: {
modules: true,
},
},
// ... Hope this helps someone else in the same situation. |
Instead of using "compileType", the |
Other:
sass-loader: "8.0.2",
style-loader: "1.2.1",
Expected Behavior
In version CSS-loader 3.x.x I was able to import SCSS variables but since I migrated to css-loader 4.x.x this no longer works, now I get an empty object.
Example:
webpack.config.js
_export.scss
somefile.js
With css-loader 3.x.x and older everything works fine as expected. I get variables as an object containing the values
{
whitecolor: "#fcf5ed";
darkcolor: "#402f2b";
lightcolor: "#e6d5c3"
}
Actual Behavior
Since migrated to css-loader 4.x.x instead of the expected values I get an empty object {}
If I role back to an older version of css-loader everything works again as expected.
Code
This is a full copy of my webpack.config.js
How Do We Reproduce?
Just try to export some variables in a scss files and import in a js file. It all works fine with css-loader 3.x.x or older.
With css-loader 4.x.x the imported variables are object is and empty object.
The text was updated successfully, but these errors were encountered: