- Error
- Reported by the type checker
TS2307
Cannot find module '{0}' or its corresponding type declarations.
An import's module can't be found: the package isn't installed, the path is wrong, or it has no type declarations.
What it means
Module resolution found no file for the specifier, neither a TypeScript file, a .d.ts, nor a package with types. The resolution rules depend on module and moduleResolution in tsconfig.json.
Example
import { format } from "./utils/date";
export const today = format(new Date());
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(1,24): error TS2307: Cannot find module './utils/date' or its corresponding type declarations.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Check the relative path and the file's extension.
- Install the package (and its
@types/package if it ships no types). - Check
paths,baseUrlandmoduleResolutionin tsconfig.json.