EISDIR node filesystem ai_generated true

Error: EISDIR: illegal operation on a directory, read

ID: node/err-fs-eisdir

Also available as: JSON · Markdown
97%Fix Rate
98%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Attempting to read/write a directory as if it were a file.

generic

Workarounds

  1. 95% success Check if the path is a file: fs.statSync(path).isFile() before reading
    Use lstatSync to not follow symlinks
  2. 97% success Fix the path to point to the actual file, not its parent directory
    Common when path.join or path.resolve produces a directory path instead of file path

Dead Ends

Common approaches that don't work:

  1. Adding recursive option to the read call 80% fail

    fs.readFile doesn't support reading directories; recursive is for mkdir/rmdir

  2. Catching the error and skipping 70% fail

    The file you need isn't being read; the feature is broken

Error Chain

Frequently confused with: