Skip to content
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

Module '"*.module.css"' has no exported member '[class]'. Did you mean to use 'import [class] from "*.module.css"' instead? ts(2614) #281

Open
ruziev-dev opened this issue Jan 30, 2025 · 2 comments

Comments

@ruziev-dev
Copy link

I'm using Vite (React+TypeScript template) and try to set up typed import CSS Modules. But I can't import any exactly class

test.module.css

.testCssClass {
    color: greenyellow;
}

When I using it there are some problems. I can import CSS module as CSSModuleClasses but it doesn't have known keys for TypeScript

Image

Image

Module '"*.module.css"' has no exported member 'testCssClass'. Did you mean to use 'import testCssClass from "*.module.css"' instead? ts(2614)

Image

Image

I'have tried to use typescript-plugin-css-modules in tsconfig.json

"compilerOptions": {
        "plugins": [
            {
                "name": "typescript-plugin-css-modules",
            }
        ]
    }

But it doesn't help.

@wesbos
Copy link

wesbos commented Jan 30, 2025

Try include your CSS modules in your tsconfig:

  "include": [ "**/*.module.css"],

@Ch-Valentine
Copy link

@ruziev-dev this package doesn't support latest css-loader, and it uses deprecated webpack loader API, I switched to another package: https://www.npmjs.com/package/css-modules-dts-loader,

{
    loader: require.resolve("css-modules-dts-loader"),
    options: {
        camelCase: true,
        quote: "double",
        indentStyle: "space",
        indentSize: 4,
        sort: true,
        mode: isProduction ? "verify" : "emit"
    }
}

and css-loader started set namedExport prop as true by the default, you have to import css loaders by the new way: from import styles from ... to import * as styles from ...

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

No branches or pull requests

3 participants