{"record":{"id":"fba65545d4173b5b","repo":"denoland/deno","slug":"esbuild-exited-before-the-rebuild-completed","errorCode":null,"errorMessage":"esbuild exited before the rebuild completed","messagePattern":"esbuild exited before the rebuild completed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/bundle/mod.rs","lineNumber":1185,"sourceCode":"\n    Ok(response)\n  }\n\n  async fn rebuild(&mut self) -> Result<BuildResponse, AnyError> {\n    match self.mode {\n      BundlingMode::OneShot => {\n        panic!(\"rebuild not supported for one-shot mode\")\n      }\n      BundlingMode::Watch => {\n        log::trace!(\"sending rebuild request\");\n        let _response = self\n          .client\n          .send_rebuild_request(0)\n          .await\n          .context(\"failed to send rebuild request to esbuild\")?\n          .map_err(|e| message_to_error(&e, &self.cwd))?;\n        let response = self.on_end_rx.recv().await.ok_or_else(|| {\n          deno_core::anyhow::anyhow!(\n            \"esbuild exited before the rebuild completed\"\n          )\n        })?;\n        Ok(response.into())\n      }\n    }\n  }\n\n  async fn reload_specifiers(\n    &mut self,\n    changed_paths: &[PathBuf],\n  ) -> Result<(), AnyError> {\n    self.reload_html_entrypoints(changed_paths)?;\n    self.plugin_handler.reload_specifiers(changed_paths).await?;\n    Ok(())\n  }\n\n  fn reload_html_entrypoints(","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/bundle/mod.rs#L1167-L1203","documentation":"In watch mode, a rebuild sends a rebuild request to the persistent esbuild child process and then awaits its on_end event over a channel; recv() returning None means every sender was dropped - the esbuild process exited (crashed, was killed, binary vanished) before the rebuild finished (cli/tools/bundle/mod.rs:1176-1189).","triggerScenarios":"The esbuild child crashes mid-rebuild (native crash, OOM kill on constrained CI containers); the DENO_DIR-cached esbuild binary is deleted or corrupted while watching; system shutting down and the process group being torn down.","commonSituations":"Long watch sessions on memory-limited containers/CI where the kernel OOM-kills esbuild; antivirus/cleanup tools purging cache directories during the session; corrupted binary after a partial install (the atomic-rename logic guards this, but external deletion is still possible).","solutions":["Restart the watch session (deno bundle --watch ...) - the child is respawned on startup","Check for OOM kills: dmesg | grep -i oom or container memory limits; raise the limit or reduce --minify/workload","Delete the cached esbuild binary directory under DENO_DIR so the next start re-downloads a clean copy","If it recurs on current Deno with a reproducible trigger, report to denoland/deno with the esbuild version pin"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Verify the cached esbuild binary is present and executable before long watch sessions\nBIN_DIR=$(deno info 2>/dev/null | sed -n 's/.*DENO_DIR[^ ]* //p')\nfind \"${DENO_DIR:-$HOME/.cache/deno}\" -name esbuild -type f -executable -print 2>/dev/null || echo 'no cached esbuild binary - expect first-run download'","typeGuard":null,"tryCatchPattern":"# Supervised watch: restart the session when esbuild dies mid-rebuild\nuntil deno bundle --watch --outdir dist src/main.ts; do\n  echo 'watch session died; restarting in 3s' >&2\n  if dmesg 2>/dev/null | grep -qi 'oom.*esbuild'; then echo 'OOM kill detected - raise memory limit' >&2; exit 1; fi\n  sleep 3\ndone","preventionTips":["Give CI containers enough memory for esbuild during watch/rebuild","Exclude DENO_DIR from cleanup/antivirus scans during long sessions","Prefer fresh watch sessions over multi-day ones; restart after upgrades"],"tags":["bundle","watch-mode","esbuild","process-crash","oom"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}