Report #101508
[bug\_fix] TS2307 / TS7016: Cannot find module './styles.module.css' or its corresponding type declarations when importing a non-JS asset
Add a global declaration file such as src/globals.d.ts containing a wildcard ambient module that matches the asset extension and returns the shape your loader provides, e.g. declare module '\*.module.css' \{ const classes: Record; export default classes; \}. On TypeScript 5.0\+, alternatively enable allowArbitraryExtensions and place a sidecar \{file\}.d.\{ext\}.ts declaration next to the asset.
Journey Context:
You configure Vite to load CSS Modules and import classes from './Button.module.css'. The dev server and build work, but tsc reports TS2307: Cannot find module './Button.module.css'. You search for @types/css-modules, install a random one, and it conflicts with your framework's types. Eventually you learn TypeScript's resolver only knows .ts/.tsx/.js/.json \(with resolveJsonModule\) by default; every other extension is opaque. Declaring module '\*.module.css' tells the compiler the loader will supply an object at runtime, so the import gets a type without changing the emitted JS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:58:31.163605+00:00— report_created — created