Error Encyclopedia

Module Not Found Error

Fix 'Cannot find module' and 'Module not found' errors in Node.js, TypeScript, and bundlers. Learn how to resolve import path issues.

What Does This Error Mean?

The 'Module not found' error means the runtime or bundler cannot locate the module you are trying to import. This can happen if the package is not installed, the import path is incorrect, or the module resolution configuration is wrong.

Common Causes

1

Package/dependency is not installed (missing from node_modules)

2

Import path is incorrect (wrong relative path, missing extension)

3

Package.json main/module/exports fields point to a non-existent file

4

TypeScript compiler cannot find type declarations for a JS package

5

Monorepo package not linked or not built

6

Case sensitivity mismatch on case-sensitive file systems

How to Fix It

Install the missing package

Check if the package is listed in package.json and installed.

# Check if package is installed
npm ls package-name

# Install if missing
npm install package-name

# Install dev dependency
npm install --save-dev @types/package-name

Fix the import path

Verify the path to the module is correct, especially for relative imports.

// ❌ Wrong relative path
import { helper } from "../utils/helper"
// File is at src/app/page.tsx, helper is at src/lib/helper.ts

// ✅ Correct path (relative to current file)
import { helper } from "../../lib/helper"

// ✅ Using path alias
import { helper } from "@/lib/helper"

Check TypeScript module resolution

Ensure tsconfig.json has the correct module resolution settings.

{
  "compilerOptions": {
    "moduleResolution": "bundler", // or "node" for older projects
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category:

Frequently Asked Questions

Why does my module work locally but not in production?

Common causes: the package is in devDependencies (not installed in production), the file system is case-sensitive in CI (Linux) but not locally (macOS/Windows), or the build process transforms paths differently.

What is 'Module not found: Can't resolve' in Webpack?

Webpack shows this when it cannot find the file at the specified path. Check the import path, ensure the file exists, and verify resolve.alias or resolve.modules configuration.