{"record":{"id":"fe84d19b7fc8c285","repo":"oven-sh/bun","slug":"file-did-not-exist-after-write-outputpath","errorCode":null,"errorMessage":"file did not exist after write: ${outputPath}","messagePattern":"file did not exist after write: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/bundle-modules.ts","lineNumber":187,"sourceCode":"      },\n    );\n    if (!exportOptimization) {\n      fileToTranspile = `var $;` + fileToTranspile.replaceAll(\"__intrinsic__exports\", \"$\");\n    }\n    const outputPath = path.join(TMP_DIR, moduleList[i].slice(0, -3) + \".ts\");\n\n    await mkdir(path.dirname(outputPath), { recursive: true });\n    if (!fs.existsSync(path.dirname(outputPath))) {\n      verbose(\"directory did not exist after mkdir twice:\", path.dirname(outputPath));\n    }\n\n    fileToTranspile = \"// @ts-nocheck\\n\" + fileToTranspile;\n\n    try {\n      await writeFile(outputPath, fileToTranspile);\n      if (!fs.existsSync(outputPath)) {\n        verbose(\"file did not exist after write:\", outputPath);\n        throw new Error(\"file did not exist after write: \" + outputPath);\n      }\n      verbose(\"wrote to\", outputPath, \"successfully\");\n    } catch {\n      await retry(3, async () => {\n        await mkdir(path.dirname(outputPath), { recursive: true });\n        await writeFile(outputPath, fileToTranspile);\n        if (!fs.existsSync(outputPath)) {\n          verbose(\"file did not exist after write:\", outputPath);\n          throw new Error(\"file did not exist after write: \" + outputPath);\n        }\n        verbose(\"wrote to\", outputPath, \"successfully later\");\n      });\n    }\n    bundledEntryPoints.push(outputPath);\n  } catch (error) {\n    console.error(error);\n    console.error(`While processing: ${moduleList[i]}`);\n    process.exit(1);","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/bundle-modules.ts#L169-L205","documentation":"Thrown by Bun's builtin-module codegen (src/codegen/bundle-modules.ts) when a transpiled module file is written to the temp output directory but immediately fails an fs.existsSync check. The write() promise resolved, so the filesystem silently dropped or hid the file — this is an environment-level write-visibility failure, not a code bug. The script treats it as fatal for that module, but an outer retry(3, ...) path (error 321) attempts recovery.","triggerScenarios":"Running `bun run build` / bundle-modules codegen when the temp output directory sits on a slow or filtered filesystem: antivirus/EDR locking freshly written files, OneDrive/Dropbox sync folders removing or delaying files, disk-full or quota exhaustion, or Windows MAX_PATH overflows from the deep TMP_DIR/modules_out nesting.","commonSituations":"Windows dev machines with Defender real-time scanning the repo; cloned repos inside cloud-synced folders; CI runners with a nearly full disk; Docker containers with a small tmpfs /tmp.","solutions":["Re-run the build once — the immediate existsSync failure plus 3 retries all failing usually means a persistent cause, but transient AV locks do clear","Check free space and write permissions on the temp/build directory (df, and touch a file in the same dir)","Move the repository out of OneDrive/Dropbox-synced folders, or add the repo and temp dir to antivirus exclusions","On Windows, shorten the workspace path or enable long-path support (registry LongPathsEnabled) so TMP_DIR + module path stays under MAX_PATH"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight before running codegen: prove the temp dir is writable\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nconst dir = fs.mkdtempSync(`${os.tmpdir()}/codegen-preflight-`);\nfs.writeFileSync(`${dir}/probe.js`, \"probe\");\nfs.rmSync(dir, { recursive: true });\nconsole.log(\"temp dir writable\");","typeGuard":null,"tryCatchPattern":"// the script already retries; at the outer build level treat as transient once\ntry {\n  await runCodegen();\n} catch (e) {\n  if (String(e.message).startsWith(\"file did not exist after write\")) {\n    await runCodegen(); // one full retry; a second failure means a persistent FS problem\n  } else throw e;\n}","preventionTips":["Keep the repository and build temp dirs outside OneDrive/Dropbox-synced folders","Add the repo and temp directories to antivirus real-time-scan exclusions","Ensure the volume has free space and Windows long paths are enabled before large codegen builds"],"tags":["build","codegen","filesystem","windows","environment"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}