Skip to content

Typescript complains when you import from a CSS module #7

@mthaak

Description

@mthaak

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions