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.
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026