{"record":{"id":"4ac56c16d0e83963","repo":"oven-sh/bun","slug":"bunprofile-not-found-build-it-first-bun-run","errorCode":null,"errorMessage":"${bunProfile} not found — build it first (bun run build:release)","messagePattern":"(.+?) not found — build it first \\(bun run build:release\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/orderfile/generate.ts","lineNumber":195,"sourceCode":"  for (let i = 0; i < count; i++) out[i] = Number(body[i]);\n  return out;\n}\n\nexport function generateOrderFile(options: GenerateOptions): { count: number; outPath: string } {\n  const buildDir = resolve(options.buildDir);\n  const outPath = resolve(options.outPath ?? join(buildDir, \"linker.order\"));\n  const minFunctions = options.minFunctions ?? MIN_FUNCTIONS;\n  const log = (message: string) => options.verbose && console.log(message);\n\n  const darwin = process.platform === \"darwin\";\n  if (process.platform !== \"linux\" && !(darwin && process.arch === \"arm64\")) {\n    throw new Error(\"the order file tracer builds on linux x86-64/arm64 or macOS arm64\");\n  }\n\n  // The unstripped binary: its symbol table is what maps addresses back to names.\n  const bunProfile = join(buildDir, options.exeName ?? \"bun-profile\");\n  if (!existsSync(bunProfile)) {\n    throw new Error(`${bunProfile} not found — build it first (bun run build:release)`);\n  }\n\n  const scratch = mkdtempSync(join(tmpdir(), \"bun-orderfile-\"));\n  try {\n    // ── Build the tracer and the pty runner ───────────────────────────────────\n    const tracer = join(scratch, darwin ? \"functrace.dylib\" : \"functrace.so\");\n    const ptyrun = join(scratch, \"ptyrun\");\n    const cc = process.env.CC || \"cc\";\n    const build = runCommand(\n      darwin\n        ? [cc, \"-O2\", \"-dynamiclib\", \"-fPIC\", \"-o\", tracer, join(here, \"functrace.c\")]\n        : [cc, \"-O2\", \"-shared\", \"-fPIC\", \"-o\", tracer, join(here, \"functrace.c\"), \"-ldl\", \"-lpthread\"],\n    );\n    if (build.status !== 0) throw new Error(`failed to build the tracer with ${cc}\\n${build.stderr}`);\n    const pty = runCommand([cc, \"-O2\", \"-o\", ptyrun, join(here, \"ptyrun.c\"), ...(darwin ? [] : [\"-lutil\"])]);\n    if (pty.status !== 0) throw new Error(`failed to build the pty runner with ${cc}\\n${pty.stderr}`);\n\n    // ── Symbol table and function starts ──────────────────────────────────────","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/orderfile/generate.ts#L177-L213","documentation":"The generator needs the unstripped binary at <buildDir>/bun-profile (or the exeName override) because its symbol table maps traced addresses back to function names; existsSync failed. The message tells you to build it first with `bun run build:release`.","triggerScenarios":"Running generate before any release build; passing a wrong buildDir; an assertions build that names the profiling binary differently so the default `bun-profile` misses.","commonSituations":"Fresh clones or cleaned build dirs; scripts invoked with a stale buildDir path; custom build configurations renaming the output binary.","solutions":["Run `bun run build:release` first to produce the unstripped bun-profile","Verify the path printed in the error and fix the buildDir you passed","If your build names the binary differently, pass exeName so it resolves"],"exampleFix":"// before\ngenerateOrderFile({ buildDir: \"./build\" }); // no bun-profile there yet\n\n// after — build first, then generate (or name the binary explicitly)\n// $ bun run build:release\ngenerateOrderFile({ buildDir: \"./build\", exeName: \"bun-profile\" });","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\n\nconst buildDir = resolve(options.buildDir);\nconst bunProfile = join(buildDir, options.exeName ?? \"bun-profile\");\nif (!existsSync(bunProfile)) {\n  throw new Error(`${bunProfile} missing — run \\`bun run build:release\\` before generating the order file`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chain orderfile generation directly after the release build in one CI step so the artifact always exists","When builds rename the profiling binary, wire that name through exeName instead of relying on the default"],"tags":["build","filesystem","orderfile","prerequisites"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}