GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot load CSS module file which has a class named "default" after 7.x upgrade · Issue #1589 · webpack/css-loader

This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

Cannot load CSS module file which has a class named "default" after 7.x upgrade #1589

Copy link
Copy link
Closed
#1590
Closed
Cannot load CSS module file which has a class named "default" after 7.x upgrade#1589
#1590
Copy link

Description

@EvHaus
EvHaus
opened on Apr 9, 2024
Issue body actions

Bug report

After upgrading from 6.x to 7.x, some of my CSS modules files are failing to get processed. My webpack module rule is defined as:

{
  test: /\.module\.css$/,
  use: [
    'style-loader',
    {
      loader: 'css-loader',
      options: {
        modules: {
          exportLocalsConvention: 'as-is',
          namedExport: false,
        },
      },
    },
  ],
}

Actual Behavior

If my CSS modules file has .default {} CSS class defined, webpack fails to generate the build with this error:

ERROR in ../myproject/myfile.module.css (../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[7].use[1]!../myproject/myfile.module.css) 64:7
Module parse failed: Duplicate export 'default' (64:7)
File was processed with these loaders:
 * ../../node_modules/css-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| export var removeButton = `myfile__removeButton--tj82C`;
| export var removeButtonCopy = `myfile__removeButtonCopy--Y_1QO`;
> export default ___CSS_LOADER_EXPORT___;

Expected Behavior

Ideally the same behaviour as 6.x where I can have my CSS classes defined with any name.

How Do We Reproduce?

Add the module rule configuration pasted above to your webpack config. Then create and import the following CSS file:

# myfile.module.css
.default { background: red }

Via some JavaScript asset:

# myfile.js
import styles from './myfile.module.css';

Run the webpack build via: webpack --config ./webpack.config.js.

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 93.02 MB / 32.00 GB
  Binaries:
    Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.12.0/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
  Browsers:
    Chrome: 123.0.6312.107
    Chrome Canary: 125.0.6408.0
    Edge: 123.0.2420.81
    Firefox: 123.0
    Safari: 17.4.1
Reacted by Luciano Frizzera, Николай Юськов and Ahmed Fasih
Reacted by Ahmed Fasih

Activity

  1. alexander-akait commented on Apr 10, 2024

    @alexander-akait
    alexander-akait
    on Apr 10, 2024
    Member
    More actions

    You can't use default as a class name, it is a limitation, because we have default export in ECMA modules, we need to document it

    Reacted by Николай Юськов
  2. alexander-akait commented on Apr 10, 2024

    @alexander-akait
    alexander-akait
    on Apr 10, 2024
    Member
    More actions

    Fix - #1590, I improved logic and now we rename default class to _default automatically to avoid crash, also updated docs

    Reacted by Николай Юськов
  3. alexander-akait commented on Apr 10, 2024

    @alexander-akait
    alexander-akait
    on Apr 10, 2024
    Member
    More actions

    Anyway I added test case with:

    {
      test: /\.module\.css$/,
      use: [
        'style-loader',
        {
          loader: 'css-loader',
          options: {
            modules: {
              exportLocalsConvention: 'as-is',
              namedExport: false,
            },
          },
        },
      ],
    }
    

    And can't reproduce the problem, maybe you forget to apply these options in another place

    Anyway feel free to feedback (or provide reproducible test repo)

    Reacted by Николай Юськов
  4. alexander-akait
    closed this as completedin #1590on Apr 10, 2024
  5. EvHaus commented on Apr 11, 2024

    @EvHaus
    EvHaus
    on Apr 11, 2024
    Author
    More actions

    @alexander-akait Thanks for making that change. Can you help me understand why this change was made in v7? Since a CSS Modules file is returned as an object I don't understand how a class called default would ever conflict with any ES keywords. It worked just fine in v6.

    I would understand if the class name was something like .isPrototypeOf or .constructor, but .default isn't one of the reserved keywords for JS objects:

    Screenshot 2024-04-11 at 1 23 09 PM
  6. alexander-akait commented on Apr 12, 2024

    @alexander-akait
    alexander-akait
    on Apr 12, 2024
    Member
    More actions

    You should not have problems with namedExport: false,, I added test and all everything fine, maybe you have more loaders/plugins, can you create minimum reproducible test repo?

  7. EvHaus commented on Apr 12, 2024

    @EvHaus
    EvHaus
    on Apr 12, 2024
    Author
    More actions

    Ah, you're right. My bad. I saw the docs still said .default gets remapped to _default, but it's not the case with namedExport: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.