css-modules-typescript-loader icon indicating copy to clipboard operation
css-modules-typescript-loader copied to clipboard

Not working with css-loader 7.1.2

Open diabhoil opened this issue 1 year ago • 6 comments

When using the newest version of the css-loader (7.1.2) I could not generate the files correctly.

The *.sass.d.ts files where "empty":

// This file is automatically generated.
// Please do not change this file!
interface CssExports {
}
export const cssExports: CssExports;
export default cssExports;

After changing the version of css-loader to 6.8.1 everything was working like excepted. The output of the newest css-loader version is looking a bit different to the output of the older version.

diabhoil avatar Jun 03 '24 06:06 diabhoil

I encountered the same problem

ilyabaykalov avatar Sep 10 '24 15:09 ilyabaykalov

Same here, using version 6 fixed it for me. Thanks!

Andrei15193 avatar Oct 27 '24 10:10 Andrei15193

Starting with v7, you need to set modules.namedExport to false to keep it working

kirilldronkin avatar Jan 21 '25 10:01 kirilldronkin

if you need to use named export, you can use css-modules-dts-loader

Ch-Valentine avatar Feb 17 '25 23:02 Ch-Valentine

It worked after I set the css-loader option esModule to false.

It seems that this project requires css-loader exports an object containing CSS name fields as the default export. As of now, css-loader exports CSS name fields as individual exports (not default export). To deactivate this feature you need to add something like

{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
"css-modules-typescript-loader",
{
  loader: "css-loader",
  options: {
    modules: true,
    esModule: false
  }
},
"sass-loader"
]
}

Or like

{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
"css-modules-typescript-loader",
{
  loader: "css-loader",
  options: {
    modules: { mode: "local", namedExport: false },
  }
},
"sass-loader"
]
}

to the webpack module rules config.

torahappy avatar Apr 17 '25 04:04 torahappy

{
        test: /\.module\.(css|postcss|pcss|scss|sass|less|styl|sss)$/i,
        use: [
          "style-loader",
          {
            loader: "css-modules-dts-loader",
            options: {
              // Convert CSS class names to camelCase (default: false)
              camelCase: true,
              // Quote style: "single" or "double" (default: "double")
              quote: "single",
              // Indentation style: "tab" or "space" (default: "space")
              indentStyle: "space",
              // Number of spaces if indentStyle is "space" (default: 2)
              indentSize: 2,
              // Mode: "emit" to generate or "verify" to check the file (default: "emit")
              mode: isProduction ? "verify" : "emit",
              // Sort the exported class names alphabetically (default: false)
              sort: true,
              // Use named exports instead of interface (default: true), should be the same with `css-loader` namedExport option
              namedExport: true,
              // Custom banner comment at the top of the file
              banner: "// This file is automatically generated.\n// Please do not change this file!"
            }
          },
          "css-loader"
        ]
      }

vcherevatyi-smartling avatar Apr 21 '25 11:04 vcherevatyi-smartling