parcel-bundler/parcel · error · FSError

EEXIST

EEXIST

Error message

EEXIST: ${path} already exists

What it means

EEXIST raised by `ExtendedMemoryFS._mkdir` when `mkdir` is called (non-recursive) on a path that is already a directory in the in-memory FS. Mirrors Node's `fs.mkdir` collision semantics.

Source

Thrown at packages/dev/repl/src/parcel/ExtendedMemoryFS.js:146

 */
export class ExtendedMemoryFS extends MemoryFS {
  openFDs: Map<number, {|filePath: FilePath, file: File, position: number|}> =
    new Map();
  nextFD: number = 1;

  // eslint-disable-next-line
  async _mkdir(
    dir: FilePath,
    options: {recursive?: boolean, ...} = {},
  ): Promise<void> {
    let {recursive = false} = options;

    if (!recursive) {
      if (!this.dirs.has(path.dirname(dir))) {
        throw new FSError('ENOENT', path.dirname(dir), 'is not a directory');
      }
      if (this.dirs.has(dir)) {
        throw new FSError('EEXIST', dir, 'already exists');
      }
    }

    return super.mkdirp(dir);
  }

  async _rmdir(
    filePath: FilePath,
    options: {recursive?: boolean, ...} = {},
  ): Promise<void> {
    let {recursive = false} = options;

    if (!recursive) {
      if (!this.dirs.has(filePath) && !this.files.has(filePath)) {
        throw new FSError('ENOENT', filePath, 'is not a directory');
      }
      if (
        this.dirs.has(filePath) &&

View on GitHub (pinned to 59484858a1)

Solutions

  1. Check `fs.existsSync(dir)` (or `statSync`) before mkdir.
  2. Use `{recursive: true}` which is idempotent for existing dirs.
  3. Catch EEXIST specifically and treat as success when appropriate.

Example fix

// before
await fs.mkdir('/a');
// after
await fs.mkdir('/a', {recursive: true});
Defensive patterns

Strategy: validation

Validate before calling

async function ensureDir(fs, dir) {
  if (await fs.exists(dir)) return;
  await fs.mkdir(dir, { recursive: true });
}

Try / catch

try { await fs.mkdir(dir); }
catch (e) { if (e.code !== 'EEXIST') throw e; }

Prevention

When it happens

Trigger: Calling `fs.mkdir('/a')` when `/a` already exists as a directory, without `{recursive: true}`.

Common situations: Code that unconditionally creates a dir on every run; ported scripts that ignore EEXIST; double initialization of the same path.

Related errors


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