How to fix TypeScript cannot find module CSS/SCSS in Next.js
Are you getting a similar error message when you’re importing your stylesheet?
TS2307: Cannot find module './styles.css
This message can even be for SASS files.
This is happening because TypeScript only understands TypeScript files.
It has no knowledge about CSS or SCSS stylesheets. But we inform TypeScript about it.
Solution: Declare a new module
In your Next.js project, you should have a next-env.d.ts file.
Inside that file add the following declaration.
declare module '*.css';
If you want to add your SCSS files do this one
declare module '*.scss';
In the code snippets above we’re declaring a new wildcard module for your CSS and SCSS files.
This did it for me. Happy coding!
I like to tweet about TypeScript and post helpful code snippets. Follow me there if you would like some too!