I remember feeling puzzled the first time my TypeScript compiler complained about an imported .module.css file in my React code. Everything worked at runtime, but VSCode kept throwing red squiggles. To avoid confusion, I decided to create a quick fix that put an end to these errors.
Thank me by sharing on Twitter 🙏
Cannot find module ‘./MyComponent.module.css’ or its corresponding type declarations.
1. Creating a Declaration File
I started by adding a new file named custom.d.ts in my src folder. In that file, I placed this line:
declare module '*.module.css';
Because my application only needed .module.css files, I stuck with one line. However, if I had .module.scss files, I would add another line:
declare module '*.module.scss';
2. Updating My tsconfig.json
After creating custom.d.ts, I made sure my tsconfig.json included it in the include array. For instance:
UGREEN Cat 8 Ethernet Cable 6FT, High Speed Braided 40Gbps 2000Mhz Network Cord Cat8 RJ45 Shielded Indoor Heavy Duty LAN Cables Compatible for Gaming PC PS5 Xbox Modem Router 6FT
$6.99 (as of February 19, 2026 04:52 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)HP 62 Black Ink Cartridge | Works with Envy 5540, 5640, 5660, 7640, OfficeJet 5740, 8040, OfficeJet Mobile 200, 250 | Instant Ink Eligible | C2P04AN | Packaging May Vary
(as of February 19, 2026 04:52 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)AINOPE USB to USB C Cable [2-Pack, 6.6ft] 3.1A Type C Charger Fast Charging, Right Angle USB C Cable for iPhone 17 Carplay Cable, Galaxy S10+ S10 S9, Note 10 9, LG V30, Moto, iPhone 16 15 Charger Cord
$6.99 (as of February 19, 2026 04:52 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.){
"compilerOptions": {
"strict": true,
"jsx": "react",
"moduleResolution": "node",
"skipLibCheck": true
},
"include": ["src", "src/custom.d.ts"]
}
That way, TypeScript knew where to find this new declaration file.
3. Verifying in VSCode
Lastly, I restarted VSCode. The error messages about missing types for .module.css vanished. My editor’s autocompletion also improved since TypeScript recognized those modules as valid imports.
Conclusion
This approach ended my frustration over mysterious CSS module type errors. Now I feel much more confident when importing .module.css files in my React and TypeScript projects.


