parcel-bundler/parcel · error · FSError

EISDIR

EISDIR

Error message

is a directory

What it means

MemoryFS.writeFile refuses to write into a path that is registered as a directory in `this.dirs`. The error carries code EISDIR to mirror POSIX semantics. This in-memory filesystem is used for tests and virtual inputs; the guard prevents corrupting a directory entry with file contents.

Source

Thrown at packages/core/fs/src/MemoryFS.js:181

        res = symlink;
      }
    }

    if (last) {
      res = path.join(res, last);
    }

    return res;
  }

  async writeFile(
    filePath: FilePath,
    contents: Buffer | string,
    options?: ?FileOptions,
  ) {
    filePath = this._normalizePath(filePath);
    if (this.dirs.has(filePath)) {
      throw new FSError('EISDIR', filePath, 'is a directory');
    }

    let dir = path.dirname(filePath);
    if (!this.dirs.has(dir)) {
      throw new FSError('ENOENT', dir, 'does not exist');
    }

    let buffer = makeShared(contents);
    let file = this.files.get(filePath);
    let mode = (options && options.mode) || 0o666;
    if (file) {
      file.write(buffer, mode);
      this.files.set(filePath, file);
    } else {
      this.files.set(filePath, new File(buffer, mode));
    }

    await this._sendWorkerEvent({

View on GitHub (pinned to 59484858a1)

Solutions

  1. Choose a distinct file path that is not an existing directory.
  2. Remove the conflicting directory entry before writing (`rimraf`/`rmdir`).
  3. Check `fs.statSync(p).isDirectory()` before calling writeFile and branch accordingly.

Example fix

// before
await memFS.mkdirp('/proj/foo');
await memFS.writeFile('/proj/foo', 'data'); // EISDIR

// after
await memFS.mkdirp('/proj/foo');
await memFS.writeFile('/proj/foo/bar.txt', 'data');
Defensive patterns

Strategy: validation

Validate before calling

async function safeWriteFile(fs, p, data) {
  const st = await fs.stat(p).catch(() => null);
  if (st && st.isDirectory()) throw new Error(`Refusing to write: ${p} is a directory`);
  return fs.writeFile(p, data);
}

Type guard

function pathIsNotADirectorySync(fs, p) {
  try { return !fs.statSync(p).isDirectory(); } catch { return true; }
}

Try / catch

try { await memFS.writeFile(p, data); } catch (e) {
  if (e.code === 'EISDIR') { console.error(`${p} is a directory; pick a file path`); } else throw e;
}

Prevention

When it happens

Trigger: Calling `memoryFS.writeFile(dirPath, ...)` where dirPath was previously created with mkdir/mkdirp and is tracked in `this.dirs`.

Common situations: Test harness writing a file at a path that was already registered as a directory; path normalization mismatch where a directory and file share a key; bundler internals attempting to write an output whose path collides with a created dir.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/097a0069a54db64d. Report an issue: GitHub.