Error: ENOENT: no such file or directory
A file or directory the program tried to open doesn’t exist at that path.
no such file or directoryspawn ENOENTnpm ERR! enoent 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 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
- nodemon crashed [nodemon] app crashed - waiting for file changes before starting...
- UnhandledPromiseRejection Node.js: [UnhandledPromiseRejection] — This error originated either by throwing inside of an async function without a catch block
- EBADENGINE npm WARN EBADENGINE Unsupported engine / The engine "node" is incompatible with this module
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 13 Oct 2026