{"record":{"id":"0ba5f3a6fc7914c2","repo":"oven-sh/bun","slug":"cannot-exec-build-mode-produced-no-executable","errorCode":null,"errorMessage":"Cannot exec: build mode produced no executable","messagePattern":"Cannot exec: build mode produced no executable","errorType":"exception","errorClass":"BuildError","httpStatus":null,"severity":"error","filePath":"scripts/build.ts","lineNumber":293,"sourceCode":"      process.exit(ninja.status ?? 1);\n    }\n\n    if (args.execArgs.length === 0) {\n      // Closing line on success: when restat prunes most of the graph\n      // (local WebKit no-op shows `[1/555] build WebKit` then silence),\n      // it's not obvious ninja finished vs. stalled. This disambiguates.\n      // Targets named when explicit so it's clear what was actually built.\n      const what = args.ninjaTargets.length > 0 ? ` ${args.ninjaTargets.map(t => nameColor(t)).join(\", \")}` : \"\";\n      status(`[build]${what} done`);\n      process.exit(0);\n    }\n\n    // Exec the built binary. result.output.exe is the linked (unstripped)\n    // binary — bun-debug for debug, bun-profile for release. That's the one\n    // you want for dev iteration (has symbols + assertions in debug).\n    const exe = result.output.exe;\n    if (exe === undefined) {\n      throw new BuildError(\"Cannot exec: build mode produced no executable\", {\n        hint: `mode=${result.cfg.mode} builds artifacts, not a runnable binary. Drop the positional args or use --profile=debug.`,\n      });\n    }\n    const child = spawnSync(exe, args.execArgs, { stdio: \"inherit\" });\n    if (child.error) {\n      throw new BuildError(`Failed to exec ${exe}`, { cause: child.error });\n    }\n    // Signal death: re-raise so our parent sees the same signal (shells\n    // show \"Segmentation fault\" etc. based on this, not exit code).\n    if (child.signal) {\n      process.kill(process.pid, child.signal);\n      return;\n    }\n    process.exit(child.status ?? 0);\n  }\n}\n\n/**","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/build.ts#L275-L311","documentation":"After a successful ninja build, scripts/build.ts execs the freshly linked binary with any trailing positional args. This BuildError fires when result.output.exe is undefined — the chosen mode builds artifacts rather than a host-runnable executable (the comment notes exe is bun-debug in debug, bun-profile in release).","triggerScenarios":"Passing exec args to an artifact-only mode — e.g. bun run build windows-x64 <args...> on a non-Windows host (cross-compile output cannot run here), or a target/profile whose output is objects or a library rather than the bun binary.","commonSituations":"Cross-compiling Windows builds from Linux/macOS and leaving trailing args on the command; using --target with positional exec args; copying a `bun bd test ...` invocation onto a cross-compile profile.","solutions":["Drop the positional/exec args — build only: bun run build windows-x64","Or pick a runnable profile: add --profile=debug (produces bun-debug) before the exec args","Check the mode named in the hint to confirm which profile produced artifacts"],"exampleFix":"# before — exec args on an artifact-only mode\n$ bun run build windows-x64 test/js/foo.test.ts\nBuildError: Cannot exec: build mode produced no executable\n\n# after — build only, no exec args\n$ bun run build windows-x64\n# or run tests with a runnable profile\n$ bun bd test js/foo.test.ts","handlingStrategy":"validation","validationCode":"// before build-then-exec, make sure the mode yields a host-runnable binary\nconst profile = process.argv.find(a => a.startsWith(\"--profile=\"))?.slice(9) ?? \"debug\";\nconst artifactOnly = /windows-(x64|arm64)/.test(profile); // cross-compile from non-Windows hosts\nconst hasExecArgs = process.argv.slice(2).some(a => !a.startsWith(\"-\"));\nif (hasExecArgs && artifactOnly) {\n  console.error(\"refusing: artifact-only profile cannot exec; remove trailing args\");\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep build-only and build-then-exec commands in separate npm scripts","Cross-compile profiles never exec — do not reuse `bd test ...` muscle memory on them"],"tags":["build","cli","usage","cross-compile"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}