TS2307
TypeScriptERRORNotableModulesHIGH confidence

Cannot find module

What this means

TypeScript could not locate a module that is being imported.

Why it happens
  1. 1The path to the module is incorrect.
  2. 2The module name has a typo.
  3. 3The module exists, but its type declarations are missing and it is not a plain JavaScript module.
How to reproduce

An import statement references a file that does not exist.

trigger — this will error
trigger — this will error
import { a } from "./non-existent-file";

expected output

error TS2307: Cannot find module './non-existent-file' or its corresponding type declarations.

Fix 1

Correct the module path

WHEN The path to the file is wrong.

Correct the module path
import { a } from "./existent-file";

Why this works

Providing the correct relative or absolute path to the module file.

Fix 2

Install the module and its types

WHEN The module is an external dependency that is not installed.

Install the module and its types
// First run: npm install <module-name>
// Then in your code:
import { a } from "<module-name>";

Why this works

Installing the package makes it available to the module resolution system.

What not to do

Create an empty module declaration with 'declare module'

This silences the error but provides no type safety, effectively treating the module as 'any'.

Sources
Official documentation ↗

microsoft/TypeScript src/compiler/diagnosticMessages.json

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors