alexeagleson / template-react-component-library

A component library for React
308 stars 128 forks source link

Typescript complains when you import from a CSS module #7

Open mthaak opened 2 years ago

mthaak commented 2 years ago

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!

vunguyen10111995 commented 1 year ago

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


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