ProjectStack
typescript

TS2307: Cannot find module 'X' or its corresponding type declarations

TypeScript can't locate the module you're importing — either the package isn't installed, the path is wrong, or the module exists but doesn't have TypeScript type definitions. Without types, TypeScript can't type-check your usage of the module.

Common causes

  • The npm package isn't installed — run npm install to get it
  • The @types package for the library isn't installed (e.g., @types/express for express)
  • A relative import path is wrong or the file doesn't exist at that path
  • The module's package.json doesn't include a types field and there's no DefinitelyTyped package

How to fix it

  1. Install the package if missing: npm install package-name
  2. Install type declarations: npm install --save-dev @types/package-name
  3. Check the relative import path — make sure the file exists and the path is correct
  4. If no @types package exists, add a declaration file: create module.d.ts with declare module 'module-name'

Example

import express from 'express'; // error TS2307: Cannot find module 'express' or its corresponding type declarations.

Importing express before installing @types/express alongside the package

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.