Error: Cannot find module 'x' (MODULE_NOT_FOUND)
Node can’t resolve the module path — the package isn’t installed, or a relative path/extension is wrong.
Cannot find moduleModule not found: Error: Can't resolve Meaning
For package names, Node looks in node_modules up the directory tree. For relative paths it needs the exact file — and in ES modules, the file extension (./utils.js).
Common causes
npm installnot run (fresh clone, CI, Docker)- Package in devDependencies but installed with
--production - Wrong relative path or case (Linux is case-sensitive)
- Missing
.jsextension in ESM imports - Running from a different working directory
- Corrupted node_modules
⚡ Quick fix
npm install(ornpm ci)- Fix relative path/case; add
.jsin ESM - Delete
node_modulesand lockfile issues:rm -rf node_modules && npm ci - Move runtime packages to
dependencies
Detailed fix by platform
Node.js
- ESM:
import { x } from './lib/x.js'— extension required.
Docker
- Copy package*.json and run
npm ciin the image; don’t mount an empty host node_modules over it.
How to diagnose
- Name — Package or relative path?
- Installed — Present in node_modules?
- Path/case — Exact file exists with that case?
- CWD — Running from the project root?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Node.js
- ERR_TLS_CERT_ALTNAME_INVALID Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames
- MaxListenersExceededWarning MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 listeners added
- MongoServerSelectionError MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 14 Oct 2026