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.

v4.0.0 of css-module has broken ability to use mini-css-extract-plugin with css modules.

See original GitHub issue
  • Operating System: Windows 10
  • Node Version: 14.3.0
  • NPM Version: 6.14.5
  • webpack Version: 4.43.0
  • mini-css-extract-plugin Version: 0.9.0

Expected Behavior

Continue to get named exports.

Actual Behavior

No named exports!

Code

// some-css.css
.some-class { color: red; }
// some-js.js
import { someClass } from './some-css'
console.log(someClass) // expected:  some generated class name
// webpack.config.js
// this is a snippet of the loader section
// also of note is that `new MiniCssExtractPlugin()` in the plugins section is also commented out.

{
  test: /\.css$/,
  use: [
    // MiniCssExtractPlugin.loader,
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
        esModule: true,
        modules: {
          namedExport: true,
          exportLocalsConvention: 'camelCaseOnly',
        },
      },
    },
  ],
},

After uncommenting MiniCssExtractPlugin.loader and new MiniCssExtractPlugin() in plugins section, the export no longer comes forward. The object returned from that entire module is {} and so the class names aren’t coming through.

How Do We Reproduce?

You can clone this repo : https://github.com/tswaters/css-loader-4-0-0-mini-extract-issue

The readme should be pretty self-explanatory – but

  • npm start and you’ll see the index.js file console.logs undefined.
  • comment out the mini-css-extract-plugin lines in webpack.config.js and try again, it will log out properly… but, no css file.
  • git checkout ., git checkout old-version-of-css-loader, and npm ci – npm start will now output the class name properly, and the css is output

I’m not sure if If I’m missing some kind of configuration option with css-loader or if it’s a bug with mini-css-extract-plugin or some combination of configuration between these two modules that is breaking things…

I had a heck of a time just getting the exports to work properly again under v4.0.0 – but can’t seem to get mini-css-extract-plugin to not interfere with the names exports showing up in generated bundle.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
alexander-akaitcommented, Jul 28, 2020

@tswaters sometimes using search is not bad idea 😄

0reactions
alexander-akaitcommented, Jul 29, 2020

@gpoitch we keep this issue in css-loader because it can potential change output, don’t worry it will be implemented in near future

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-loader from 3.6 to 4 broke loading prior path to fonts
I just disabled the URL resolver for css-loader and overcame my exception ... files the relative path to these images is no longer...
Read more >
MiniCssExtractPlugin - webpack
It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS and SourceMaps. It builds on top of...
Read more >
Separating CSS - SurviveJS
Webpack provides a means to generate a separate CSS bundles using mini-css-extract-plugin (MCEP). It can aggregate multiple CSS files into one.
Read more >
css-loader | Yarn - Package Manager
Using global value requires you to specify :local classes. Using pure value requires selectors must contain at least one local class or id....
Read more >
CSS Modules with React: The Complete Guide | by Suraj KC
CSS module is basically css files in which class names are scoped ... CSS modules is ability to export variables from CSS file...
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