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

Typescript complains when you import from a CSS module #7

Open
mthaak opened this issue Jul 22, 2022 · 1 comment
Open

Typescript complains when you import from a CSS module #7

mthaak opened this issue Jul 22, 2022 · 1 comment

Comments

@mthaak
Copy link

mthaak commented Jul 22, 2022

After following the guide for adding Typescript here I was still getting the following error when trying to import from a CSS module

(!) Plugin typescript: @rollup/plugin-typescript TS2307: Cannot find module './Component.module.scss' or its corresponding type declarations.
src/components/Component/Component.tsx: (3:20)

import styles from "./Component.module.scss"

I fixed this by adding a typings.d.ts file to the src directory with the following contents:

declare module "*.module.css";
declare module "*.module.scss";

I based this solution on this SO thread.

Hopefully this can be added to this project and help others. Thanks!

@mthaak mthaak changed the title Import from CSS modules not understood by Typescript Typescript complains when you import from a CSS module Jul 22, 2022
@vunguyen10111995
Copy link

In tsconfig.json, you need to add this line:

"include": ["./typings.d.ts"]

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

2 participants