Skip to content
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

Regression from css-loader@4 on exported variables behavior #1262

Closed
ghoullier opened this issue Feb 11, 2021 · 3 comments · Fixed by #1263
Closed

Regression from css-loader@4 on exported variables behavior #1262

ghoullier opened this issue Feb 11, 2021 · 3 comments · Fixed by #1263

Comments

@ghoullier
Copy link

  • Operating System: 'Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64'
  • Node Version: 12.16.0
  • NPM Version: 6.13.4
  • webpack Version: 5.21.2
  • css-loader Version: >=4.0

Expected Behavior

Before css-loader@4 exported variables with the block :export {} could be imported in a JavaScript file.
The imported variables in the JavaScript land contains all exported variables in the scss file.

I've detect this problem with a migration from react-scripts@3 to react-scripts@4. After some investigations the problem seems coming from css-loader and not sass-loader itself.

A related issue in the create-react-app repository.

Actual Behavior

From css-loader@4 the imported variables is empty.

Code

webpack.config.js

$white: '#FFF';

:export {
  white: $white
}
import colors from './colors.scss';

// expected 1 but got 0
console.assert(Object.keys(colors).length === 0; 

document.body.innerHTML = JSON.stringify(colors);

How Do We Reproduce?

I've created a repository with the minimal setup to reproduce the problem.

@alexander-akait
Copy link
Member

alexander-akait commented Feb 11, 2021

Fixed in v5, icss disable by default for v4, because you are using CRA you can't change options, but we have the modules.auto and module.compileType options, these options enable module or icss output based on filename, so update css-loader to v5 and rename colors.scss to colors.icss.scss, I will update docs about the modules.auto option

@alexander-akait
Copy link
Member

Anyway if you found how you can change the compileType options to the icss value, all will work fine

@ghoullier
Copy link
Author

Thanks for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants