parcel-bundler/parcel · error · FSError

ENOENT

ENOENT

Error message

ENOENT: ${path} is not a directory

What it means

Posix-style ENOENT raised by `ExtendedMemoryFS._mkdir` when `mkdir` is called without `recursive: true` and the parent directory does not exist in the in-memory FS. Mirrors Node's `fs.mkdir` semantics inside the REPL's MemoryFS.

Source

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

/**
 * Can be used as a standin for the npm `require("fs")` package because `MemoryFS` not API compatible.
 */
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');

View on GitHub (pinned to 59484858a1)

Solutions

  1. Create parent directories first, or pass `{recursive: true}`.
  2. Use `fs.mkdirp` if available on the FS instance.
  3. Pre-seed the memory FS with expected directory structure before the operation.

Example fix

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

Strategy: validation

Validate before calling

async function safeMkdir(fs, dir) {
  const parent = path.dirname(dir);
  if (!(await fs.exists(parent))) throw new Error(`missing parent ${parent}`);
  return fs.mkdir(dir, { recursive: true });
}

Try / catch

try { await fs.mkdir(dir); }
catch (e) { if (e.code === 'ENOENT') await fs.mkdir(dir, { recursive: true }); else throw e; }

Prevention

When it happens

Trigger: Calling `fs.mkdir('/a/b')` when `/a` is not present, without `{recursive: true}`. Common from tooling that assumes parents already exist.

Common situations: A packager/transformer in the REPL calls mkdir on a nested path before creating ancestors; ported Node code that relied on real node_modules structure.

Related errors


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