{"record":{"id":"92349cf10a4a7a32","repo":"oven-sh/bun","slug":"executable-not-found-bunx-or-npx","errorCode":null,"errorMessage":"Executable not found: bunx or npx","messagePattern":"Executable not found: bunx or npx","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":1479,"sourceCode":"  }\n\n  let bootstrapPath, agentPath, dockerfilePath;\n  if (bootstrap) {\n    bootstrapPath = resolve(\n      import.meta.dirname,\n      os === \"windows\"\n        ? \"bootstrap.ps1\"\n        : features?.includes(\"docker\")\n          ? \"../.buildkite/Dockerfile-bootstrap.sh\"\n          : \"bootstrap.sh\",\n    );\n    if (!existsSync(bootstrapPath)) {\n      throw new Error(`Script not found: ${bootstrapPath}`);\n    }\n    if (ci) {\n      const npx = which(\"bunx\") || which(\"npx\");\n      if (!npx) {\n        throw new Error(\"Executable not found: bunx or npx\");\n      }\n      const entryPath = resolve(import.meta.dirname, \"agent.mjs\");\n      const tmpPath = mkdtempSync(join(tmpdir(), \"agent-\"));\n      agentPath = join(tmpPath, \"agent.mjs\");\n      await spawnSafe($`${npx} esbuild ${entryPath} --bundle --platform=node --format=esm --outfile=${agentPath}`);\n    }\n\n    if (features?.includes(\"docker\")) {\n      dockerfilePath = resolve(import.meta.dirname, \"../.buildkite/Dockerfile\");\n\n      if (!existsSync(dockerfilePath)) {\n        throw new Error(`Dockerfile not found: ${dockerfilePath}`);\n      }\n    }\n  }\n\n  // Use Packer for Windows Azure image builds — it handles VM creation,\n  // bootstrap, sysprep, and gallery capture via WinRM (no Run Command hacks).","sourceCodeStart":1461,"sourceCodeEnd":1497,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L1461-L1497","documentation":"In CI mode (the ci flag), machine.mjs bundles agent.mjs with esbuild via `bunx` or `npx` before shipping it to the machine. It probes PATH with which() for both executables and throws when neither is found, because the bundle step cannot run.","triggerScenarios":"Running with the ci flag inside an image that has neither Bun nor Node installed, or where npm's global bin directory is missing from PATH. The check runs only when ci is truthy and bootstrap is set.","commonSituations":"Minimal Docker/CI images (e.g. slim base) without Node/Bun; a CI job where PATH is reset by a wrapper; locally simulating CI in a clean shell.","solutions":["Install Bun (provides bunx) or Node (provides npx) in the environment","Fix PATH so the installed executable resolves (check `which bunx || which npx` in the same shell)","Run without the ci flag when working locally — the esbuild bundling step is CI-only"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { spawnSync } from \"node:child_process\";\n\nconst which = (bin) => spawnSync(\"which\", [bin], { encoding: \"utf8\" }).status === 0;\nconst packer = which(\"bunx\") || which(\"npx\");\nif (ci && !packer) {\n  throw new Error(\"CI mode needs bunx or npx — install Bun or Node before running\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake Bun or Node into CI images that run machine.mjs in ci mode","Assert tool availability at job start (a `command -v bunx npx` step) instead of failing mid-run"],"tags":["ci","environment","path","dependencies","esbuild"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}