TypeScript cannot find the module for a .scss or CSS module import
Cannot find module './Button.module.scss' or its corresponding type declarations.Short answer
TypeScript only knows how to read code files, so an import of a stylesheet has no type and it reports the module as missing. The bundler handles the file, but the compiler needs a declaration. Add a wildcard ambient module for the file pattern in a .d.ts file that has no top-level import or export, and make sure tsconfig includes it.
Fix it fast
1Find out which cause you have
Check whether any .d.ts file in the project already declares the pattern, and what tsconfig includes.
grep -rn "declare module" src --include=*.d.ts npx tsc --showConfig | grep -A4 include2Match what you see, then jump to its fix
What does the error look like?
Cannot find module './Button.module.scss' or its corresponding type declarations.TS2307: Cannot find module './styles.module.css' or its corresponding type declarations.
Cause 1 of 3
No declaration exists for the file type
1Check
Search for a declaration. The grep in the first step returns nothing for these patterns.
grep -rn "module.scss" src --include=*.d.ts2Fix
Add a declaration file with a wildcard pattern. The shape of the default export is your choice; a map from class name to string is common.
// src/types/scss.d.ts
declare module "*.module.scss" {
const classes: { readonly [key: string]: string };
export default classes;
}3Verify
Run the type check.
npx tsc --noEmitConfirmed by typescriptlang.org
Cause 2 of 3
The declaration file is itself a module
1Check
A file with a top-level import or export is a module, and then declare module is a module augmentation instead of an ambient declaration. Look at the top of the file.
grep -n "^import\|^export" src/types/scss.d.ts2Fix
Remove the top-level import and export lines from that file. Inside the declare module block imports are fine.
// src/types/scss.d.ts (no top-level import or export)
declare module "*.module.scss" {
const classes: { readonly [key: string]: string };
export default classes;
}3Verify
Run the type check.
npx tsc --noEmitConfirmed by typescriptlang.org
Cause 3 of 3
tsconfig does not include the declaration file
1Check
List the files the compiler loads and see if the .d.ts file is among them.
npx tsc --listFilesOnly | grep scss.d.ts2Fix
Add its folder to include, or the file itself.
{
"include": ["src/**/*", "types/scss.d.ts"]
}3Verify
Run the type check again.
npx tsc --noEmitConfirmed by typescriptlang.org
How do I stop it coming back?
- Keep all wildcard declarations in one folder that tsconfig includes.
- Use the same pattern in the declaration as the file names, such as *.module.scss.
- Run tsc --noEmit in CI, since the bundler alone will not report type errors.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript cannot find module './logo.png' or its type declarations
TS2307: Cannot find module '../assets/hero.svg' or its corresponding type declarations.
The bundler can load an image, but TypeScript knows nothing about files that are not code.
3 causes, each with a fixWeb apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
Cypress refuses to start with 'Your configFile is invalid'
Your configFile threw an error from: /path/to/cypress.config.ts
Cypress could not load cypress.config.js or .ts, or found something wrong in it.
5 causes, each with a fixWeb apps
ESLint cannot decide which copy of the @typescript-eslint plugin to use
The message lists two file paths for the same plugin, each with the name of the config that loaded it
ESLint found the same plugin at two different file paths and will not pick one.
3 causes, each with a fix