Error: ENOTDIR: not a directory
A path treats a file as if it were a directory (e.g. file.txt/child).
Seen on:
Node.js
Meaning
Some segment in the middle of the path is a regular file. Often a bad join or a file where a folder was expected.
Common causes
- Joining a file path with another segment
- A file exists where a directory should be
- macOS .DS_Store or zip files in a directory walk
⚡ Quick fix
- Log each path segment
- Check which segment is a file
- Skip non-directories when walking trees
Detailed fix by platform
Node.js
for (const e of fs.readdirSync(dir, { withFileTypes: true })) if (e.isDirectory()) walk(path.join(dir, e.name));
How to diagnose
- Path — Which segment is a file?
- Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.
🧠 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