question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

css module `import * as` not work after upgrade to webpack5

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
monic-shixicommented, Mar 17, 2021

No problems on webpack side, if you need help please open an issue in css-loader and provide simple reproducible test repo

Ok, thanks for you response.

0reactions
alexander-akaitcommented, Mar 17, 2021

No problems on webpack side, if you need help please open an issue in css-loader and provide simple reproducible test repo

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found