parcel-bundler/parcel · error · FSError
ENOENT
ENOENT
Error message
does not exist
What it means
MemoryFS.writeFile requires the parent directory to exist (it does not auto-mkdir). It looks up `path.dirname(filePath)` in `this.dirs`; if missing it throws ENOENT. This mirrors strict POSIX open() without O_CREAT-for-parent behavior.
Source
Thrown at packages/core/fs/src/MemoryFS.js:186
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({
type: 'writeFile',
path: filePath,
entry: this.files.get(filePath),
});
View on GitHub (pinned to 59484858a1)
Solutions
- Create parent directories first with `await memFS.mkdirp(path.dirname(filePath))`.
- Use a flat output path during tests.
- Wrap writes in a helper that ensures the parent dir exists.
Example fix
// before
await memFS.writeFile('/proj/sub/file.txt', 'data'); // ENOENT on /proj/sub
// after
await memFS.mkdirp('/proj/sub');
await memFS.writeFile('/proj/sub/file.txt', 'data'); Defensive patterns
Strategy: validation
Validate before calling
import path from 'path';
async function ensureParentDir(fs, filePath) {
const dir = path.dirname(filePath);
try { await fs.stat(dir); }
catch { await fs.mkdirp(dir); }
} Type guard
async function parentExists(fs, p) {
try { await fs.stat(path.dirname(p)); return true; } catch { return false; }
} Try / catch
try { await memFS.writeFile(p, data); } catch (e) {
if (e.code === 'ENOENT') { await memFS.mkdirp(path.dirname(p)); await memFS.writeFile(p, data); } else throw e;
} Prevention
- Call mkdirp on the parent directory before writing nested paths in MemoryFS.
- Use a writeFile helper that ensures parents exist.
- Pre-create common output directories during test setup.
When it happens
Trigger: Calling writeFile to a path whose parent directory was never created in the memory FS (no prior mkdir/mkdirp).
Common situations: Test setup forgetting to mkdirp before writing nested paths; output paths computed dynamically whose parent does not exist yet; switching from NodeFS (which often auto-creates parents in Parcel's wrappers) to MemoryFS in tests.
Related errors
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/218b1284bc8e1673.
Report an issue: GitHub.