{"record":{"id":"218b1284bc8e1673","repo":"parcel-bundler/parcel","slug":"enoent","errorCode":"ENOENT","errorMessage":"does not exist","messagePattern":"does not exist","errorType":"error_code","errorClass":"FSError","httpStatus":null,"severity":"error","filePath":"packages/core/fs/src/MemoryFS.js","lineNumber":186,"sourceCode":"      res = path.join(res, last);\n    }\n\n    return res;\n  }\n\n  async writeFile(\n    filePath: FilePath,\n    contents: Buffer | string,\n    options?: ?FileOptions,\n  ) {\n    filePath = this._normalizePath(filePath);\n    if (this.dirs.has(filePath)) {\n      throw new FSError('EISDIR', filePath, 'is a directory');\n    }\n\n    let dir = path.dirname(filePath);\n    if (!this.dirs.has(dir)) {\n      throw new FSError('ENOENT', dir, 'does not exist');\n    }\n\n    let buffer = makeShared(contents);\n    let file = this.files.get(filePath);\n    let mode = (options && options.mode) || 0o666;\n    if (file) {\n      file.write(buffer, mode);\n      this.files.set(filePath, file);\n    } else {\n      this.files.set(filePath, new File(buffer, mode));\n    }\n\n    await this._sendWorkerEvent({\n      type: 'writeFile',\n      path: filePath,\n      entry: this.files.get(filePath),\n    });\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/fs/src/MemoryFS.js#L168-L204","documentation":"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.","triggerScenarios":"Calling writeFile to a path whose parent directory was never created in the memory FS (no prior mkdir/mkdirp).","commonSituations":"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.","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."],"exampleFix":"// before\nawait memFS.writeFile('/proj/sub/file.txt', 'data'); // ENOENT on /proj/sub\n\n// after\nawait memFS.mkdirp('/proj/sub');\nawait memFS.writeFile('/proj/sub/file.txt', 'data');","handlingStrategy":"validation","validationCode":"import path from 'path';\nasync function ensureParentDir(fs, filePath) {\n  const dir = path.dirname(filePath);\n  try { await fs.stat(dir); }\n  catch { await fs.mkdirp(dir); }\n}","typeGuard":"async function parentExists(fs, p) {\n  try { await fs.stat(path.dirname(p)); return true; } catch { return false; }\n}","tryCatchPattern":"try { await memFS.writeFile(p, data); } catch (e) {\n  if (e.code === 'ENOENT') { await memFS.mkdirp(path.dirname(p)); await memFS.writeFile(p, data); } else throw e;\n}","preventionTips":["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."],"tags":["parcel","memory-fs","filesystem","enoent","test"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}