css module `import * as` not work after upgrade to webpack5
See original GitHub issueBug report
I had update webpack4 to webpack5, but some css module not work.
For example:
// ...
{
test: /\.module\.css$/,
use: [
isEnvDevelopment && require.resolve('style-loader'),
isEnvProduction && require("mini-css-extract-plugin").loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
modules: {
compileType: 'module',
exportLocalsConvention: 'camelCase',
localIdentName: '[name]_[local]_[hash:8]'
},
esModule: false
}
},
// ... postcssLoader,
// ... lessLoader
].filter(Boolean)
}
// ...
/* xxx.module.css */
.root {
color: #fff;
}
not work
- env
- webpack@5.16.0
- css-loader@5.0.1
// a.jsx
import * as styles from './xxx.module.css'
import ss from './xxx.module.css'
console.log(styles) // Module {__esModule: true, Symbol(Symbol.toStringTag): "Module"}
console.log(ss) // {root: "[name]_root_[hash]"}
work
- env
- webpack@4.35.0
- css-loader@5.0.1
// a.jsx
import * as styles from './xxx.module.css'
import ss from './xxx.module.css'
console.log(styles) // {root: "[name]_root_[hash]"}
console.log(ss) // {root: "[name]_root_[hash]"}
I had read change log, so, it’s because of tree-shaking
? But i had set sideEffects: true
, that not work.
What is the current behavior?
If css imported by import * as xxx from '*.css'
, the style not work.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
import * as xxx from '*.css'
work, likes webpack5
Other relevant information: webpack version: 5.16.0 Node.js version: 12.13.1 Operating System: macOS Mojave Additional tools:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Webpack 5 and css-loader aren't compiling @value directive ...
The @value directive is a CSS module feature. I know that css-loader will by default only apply the CSS module specification to files...
Read more >How to configure CSS Modules for webpack - LogRocket Blog
Once we connect css-loader , webpack will be able to work with this import and bring our CSS files into the bundle. So,...
Read more >css-loader | webpack - JS.ORG
To import a local classname from another module. Note. We strongly recommend that you specify the extension when importing a file, since it...
Read more >How to configure CSS and CSS modules in webpack
This makes it clear to see if it works or not - if it works the whole page will be black! Next thing...
Read more >Webpack with CSS Modules - E.Y. - Medium
How is this working? We need to import the stylesheet to the JS file, and write our classname like styles[“classname”] : //JS
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, thanks for you response.
No problems on webpack side, if you need help please open an issue in
css-loader
and provide simple reproducible test repo