{"record":{"id":"097a0069a54db64d","repo":"parcel-bundler/parcel","slug":"eisdir","errorCode":"EISDIR","errorMessage":"is a directory","messagePattern":"is a directory","errorType":"error_code","errorClass":"FSError","httpStatus":null,"severity":"error","filePath":"packages/core/fs/src/MemoryFS.js","lineNumber":181,"sourceCode":"        res = symlink;\n      }\n    }\n\n    if (last) {\n      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({","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/fs/src/MemoryFS.js#L163-L199","documentation":"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.","triggerScenarios":"Calling `memoryFS.writeFile(dirPath, ...)` where dirPath was previously created with mkdir/mkdirp and is tracked in `this.dirs`.","commonSituations":"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.","solutions":["Choose a distinct file path that is not an existing directory.","Remove the conflicting directory entry before writing (`rimraf`/`rmdir`).","Check `fs.statSync(p).isDirectory()` before calling writeFile and branch accordingly."],"exampleFix":"// before\nawait memFS.mkdirp('/proj/foo');\nawait memFS.writeFile('/proj/foo', 'data'); // EISDIR\n\n// after\nawait memFS.mkdirp('/proj/foo');\nawait memFS.writeFile('/proj/foo/bar.txt', 'data');","handlingStrategy":"validation","validationCode":"async function safeWriteFile(fs, p, data) {\n  const st = await fs.stat(p).catch(() => null);\n  if (st && st.isDirectory()) throw new Error(`Refusing to write: ${p} is a directory`);\n  return fs.writeFile(p, data);\n}","typeGuard":"function pathIsNotADirectorySync(fs, p) {\n  try { return !fs.statSync(p).isDirectory(); } catch { return true; }\n}","tryCatchPattern":"try { await memFS.writeFile(p, data); } catch (e) {\n  if (e.code === 'EISDIR') { console.error(`${p} is a directory; pick a file path`); } else throw e;\n}","preventionTips":["Stat the path before writing and branch on isDirectory().","Keep file and directory namespaces disjoint in test fixtures.","Wrap MemoryFS writes in a helper that guards EISDIR."],"tags":["parcel","memory-fs","filesystem","eisdir","test"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}