TypeScript error: Cannot find module 'X' or its corresponding type declarations

Nextjs·Sep 12, 2026·beginner·
Quick answer

Either the package isn't installed, or it doesn't ship its own TypeScript types and you're missing the matching `@types/` package. Try installing `@types/<package-name>` — if that package doesn't exist either, the library likely has no type support and you'll need a manual type declaration.

What causes this error

This error covers two genuinely different problems that look identical: the package itself isn't installed, or the package exists but ships no type information and there's no separate @types package for it either.

The Fix

# 1. Confirm the package is actually installed
npm ls some-package

# 2. If installed but still erroring, try the matching types package
npm install -D @types/some-package

# 3. If no @types package exists, declare it yourself
# Create a file like src/types/some-package.d.ts:
declare module 'some-package';

Common causes / variations

  • Forgetting to run npm install after pulling changes that added a new dependency
  • A package written in plain JS with no published types and no community @types package
  • Path alias imports (@/lib/foo) not resolving because tsconfig.json's paths is misconfigured

Related errors

See also: Property does not exist on type 'never'.

Was this fix helpful?

Comments

Loading comments...

Fix: TypeScript Cannot find module or its type declarations | BugFixer | BugFixer