ENOTDIR 🟩 Node.js

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

  1. Log each path segment
  2. Check which segment is a file
  3. Skip non-directories when walking trees

Detailed fix by platform

Node.js

  1. for (const e of fs.readdirSync(dir, { withFileTypes: true })) if (e.isDirectory()) walk(path.join(dir, e.name));

How to diagnose

  1. Path — Which segment is a file?
  2. 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.