Error: ENOENT: no such file or directory
A file or directory the program tried to open doesn’t exist at that path.
Meaning
Relative paths resolve from the process’s current working directory, not the script file — so code that works from one folder fails from another. In npm, “ENOENT … package.json” means you ran npm outside the project folder.
Common causes
- Relative path resolved from a different working directory
- File not created/copied (build output, uploads, Docker COPY)
- npm command run outside the project (no package.json)
- Case mismatch on Linux
- Executable not found when spawning (
spawn git ENOENT)
⚡ Quick fix
- Build paths from the script location:
path.join(__dirname, 'data.json') - Check the exact path in the error exists
- Run npm in the folder with package.json
- For
spawn X ENOENT, install X or fix PATH
Detailed fix by platform
Node.js
- Robust path:javascript
const file = path.join(__dirname, 'config', 'settings.json');
How to diagnose
- Path — Exact path in the error
- CWD —
process.cwd()at runtime - Exists — Is the file present in this environment?
🧠 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