Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS modules not working in Codesandbox - can't find files even though they exist

I'm trying to build a project and I just moved my code from VSCode to Codesandbox. I must mention that the code was working fine in VSC but for some reason it's not working in Codesandbox - the CSS modules can't be found. I am thinking I am maybe missing something in my setup since I looked at other examples and the code seems identical (the imports). The error in getting for all the files is:

Cannot find module './Example.module.css' or its corresponding type declarations.

The complete code is here:

https://codesandbox.io/s/burger-builder-project-173uw?file=/src/Components/Layout/Layout.tsx

Does anyone have any idea what could be wrong? Thank you.


1 Answers

To get rid of the error you need to create a Typescript Declaration file for *.css on the root folder and include it on the tsconfig.json. Take a look on the changes below:

module.css.d.ts

declare module "*.module.css";

tsconfig.json

{
    "include": [
        "./src/*",
        "./module.css.d.ts"
    ],
    "compilerOptions": {
        "strict": true,
        "esModuleInterop": true,
        "lib": [
            "dom",
            "es2015"
        ],
        "jsx": "react"
    }
}
like image 186
lepsch Avatar answered Oct 18 '25 23:10

lepsch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!