Skip to content

Default camelCasing enabled by namedExport in css-loader is throwing error with typings #42

Description

@bahtou

I implemented the style-loader and css-loader combo as seen in this example: https://github.com/webpack-contrib/style-loader#modules

// styles.css
.foo-baz {
  color: red;
}
.bar {
  color: blue;
}

// index.js
import { fooBaz, bar } from './styles.css';
console.log(fooBaz, bar);

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'style-loader',
            options: {
              esModule: true,
              modules: {
                namedExport: true,
              },
            },
          },
          {
            loader: 'css-loader',
            options: {
              esModule: true,
              modules: {
                namedExport: true,
                //exportLocalsConvention: 'camelCaseOnly'  -- default when namedExport is true
              },
            },
          },
        ],
      },
    ],
  },
};

By default, using the namedExport in css-loader automatically sets the exportLocalsConvention: 'camelCaseOnly’. Note the css class foo-baz in the styles.css file and how it is imported in the index.js file (.foo-baz, fooBaz)

Applying typings-for-css-modules-loader to the webpack configuration:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'style-loader',
            options: {
              esModule: true,
              modules: {
                namedExport: true,
              },
            },
          },
          {loader: '@teamsupercell/typings-for-css-modules-loader'},
          {
            loader: 'css-loader',
            options: {
              esModule: true,
              modules: {
                namedExport: true,
                //exportLocalsConvention: 'camelCaseOnly'  -- default when namedExport is true
              },
            },
          },
        ],
      },
    ],
  },
};

The following error shows up

ERROR in [at-loader] ./index.tsx:5:10
    TS2305: Module '"./styles.css"' has no exported member 'fooBaz'.

What is the configuration missing to enable typings-for-css-modules-loader to work with the default camelCasing? Is this something the generated *.d.ts* files need to adjust for?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions