Skip to content

Can't use exportLocalsOnly in css-loader #841

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

Closed
Istanful opened this issue Oct 4, 2021 · 4 comments · Fixed by #844
Closed

Can't use exportLocalsOnly in css-loader #841

Istanful opened this issue Oct 4, 2021 · 4 comments · Fixed by #844

Comments

@Istanful
Copy link

Istanful commented Oct 4, 2021

Bug report

When I configure mini-css-extract-plugin in conjunction with css-loader and exportLocalsOnly I encounter an error.

Reproducible repo: https://github.com/Istanful/export-locals-only-mini-css-error

Actual Behavior

When I configure mini-css-extract-plugin in conjunction with css-loader and exportLocalsOnly I encounter an error.

Expected Behavior

It should ignore that no default export exists and compile anyways.

How Do We Reproduce?

I create a webpack.config.js file. This is the relevant configuration.

        {
          test: /\.css$/i,
          use: [
            {
              loader: MiniCssExtractPlugin.loader,
            },
            {
              loader: "css-loader",
              options: {
                esModule: true,
                modules: {
                  namedExport: true,
                  exportLocalsConvention: "camelCaseOnly",
                  localIdentName: "[path][name]__[local]--[hash:base64:5]",
                },
              },
            },
          ],
        },

When I then run webpack serve I get the following error:

TypeError: Cannot use 'in' operator to search for 'locals' in undefined

It happens here as it tries to check if locals is in the default export.

I wish to not have a default export as I want to only use CSS module locals.

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


  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 561.29 MB / 16.00 GB
  Binaries:
    Node: 12.18.3 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.6 - /usr/local/bin/npm
  Browsers:
    Chrome: 94.0.4606.71
    Safari: 14.1.2
  Packages:
    extract-text-webpack-plugin: ^3.0.2 => 3.0.2
    webpack: ^5.54.0 => 5.54.0
    webpack-cli: ^4.8.0 => 4.8.0
    webpack-dev-server: ^4.3.0 => 4.3.0
@alexander-akait
Copy link
Member

Please provide reproducible test repo

@Istanful
Copy link
Author

Istanful commented Oct 4, 2021

@alexander-akait
Copy link
Member

Fixed - #844, note - you should avoid using mini-css-extract-plugin with exportLocalsConvention, it just doesn't make sense because you don't have CSS inside js file, so nothing to extract, but you will decrease build time on checks inside plugin

@Istanful
Copy link
Author

Istanful commented Oct 6, 2021

Thanks! You're right, that makes sense. I did not quite think that through. :P

I'm hoping to only use scoped classes and forbidding global selectors such as body. My understanding was that exportLocalsOnly did this and mini-css-extract-plugin would split the CSS appropriately.

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