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
Package/dependency is not installed (missing from node_modules)
Import path is incorrect (wrong relative path, missing extension)
Package.json main/module/exports fields point to a non-existent file
TypeScript compiler cannot find type declarations for a JS package
Monorepo package not linked or not built
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:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.
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.