Lingua-e
JavaScript

What is a TS2307: Cannot Find Module?

← Errors

TypeScript error TS2307 is reported when a module import cannot be resolved. This happens when the package is not installed, the path is wrong, or the package lacks TypeScript type declarations.

Why it happens

  • The npm package is referenced but not installed (missing from node_modules).
  • The package exists but has no type declarations and no @types counterpart.
  • A relative path import has a typo or points to a file that does not exist.
  • The moduleResolution setting in tsconfig.json is incompatible with the package's exports field.

Examples

JavaScript

Code that triggers the error

import { format } from "date-fns";

Error output

error TS2307: Cannot find module 'date-fns' or its corresponding type declarations.

How to fix it

Run npm install for the missing package. Install @types/package-name if the package lacks built-in types. For relative imports, verify the file path and extension. Check moduleResolution: 'bundler' or 'node16' in tsconfig.json for modern packages.

Fixed code

// First install the package
// npm install date-fns
import { format } from "date-fns";

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free