{"record":{"id":"8f3aa22cee0f4834","repo":"can1357/oh-my-pi","slug":"failed-to-build-stats-client-exit-buildresult-e","errorCode":null,"errorMessage":"Failed to build stats client (exit ${buildResult.exitCode})${details}","messagePattern":"Failed to build stats client \\(exit (.+?)\\)(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stats/src/server.ts","lineNumber":174,"sourceCode":"\t\t\tcssStats.mtimeMs >= sourceMtime\n\t\t) {\n\t\t\tshouldBuild = false;\n\t\t}\n\t} catch {\n\t\tshouldBuild = true;\n\t}\n\n\tif (!shouldBuild) return;\n\n\tawait fs.rm(STATIC_DIR, { recursive: true, force: true });\n\n\tconsole.log(\"Building stats client...\");\n\tconst packageRoot = path.join(import.meta.dir, \"..\");\n\tconst buildResult = await $`bun run build.ts`.cwd(packageRoot).quiet().nothrow();\n\tif (buildResult.exitCode !== 0) {\n\t\tconst output = buildResult.text().trim();\n\t\tconst details = output ? `\\n${output}` : \"\";\n\t\tthrow new Error(`Failed to build stats client (exit ${buildResult.exitCode})${details}`);\n\t}\n\n\tconst indexHtml = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>AI Usage Statistics</title>\n    <link rel=\"stylesheet\" href=\"styles.css\">\n</head>\n<body>\n    <div id=\"root\"></div>\n    <script src=\"index.js\" type=\"module\"></script>\n</body>\n</html>`;\n\n\tawait Bun.write(path.join(STATIC_DIR, \"index.html\"), indexHtml);\n};","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/stats/src/server.ts#L156-L192","documentation":"The stats package's startServer() builds the bundled web client (build.ts) via `bun run build.ts` before serving the dashboard. If the build subprocess exits non-zero, ensureClientBuild throws this error, appending the captured build output so the underlying compile failure is visible.","triggerScenarios":"`bun run build.ts` inside packages/stats exits with a non-zero code — e.g. a TypeScript/bundler error, a missing dependency, a syntax error in client code, or a failed postbuild step.","commonSituations":"Editing client code in packages/stats and introducing a compile error; running the server in a fresh checkout where dependencies aren't installed; a broken or renamed build script; disk/permission issues in the output directory.","solutions":["Read the build output appended below the error message — it contains the actual compiler/bundler failure","Run `bun run build.ts` manually in packages/stats to reproduce and iterate on the fix","Install dependencies (`bun install`) if this is a fresh clone","Fix the underlying syntax/type/import error reported in the build output"],"exampleFix":"// before: server started without checking client build\nawait startServer({ port: 3000 })\n// after: build once yourself to surface errors directly\n$`bun run build.ts`.cwd(\"packages/stats\").nothrow(); // inspect output before startServer","handlingStrategy":"try-catch","validationCode":"const proc = Bun.spawnSync([\"bun\", \"run\", \"build.ts\"], { cwd: \"packages/stats\" });\nif (proc.exitCode !== 0) throw new Error(proc.stderr.toString());","typeGuard":null,"tryCatchPattern":"try {\n  await startServer(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Failed to build stats client\")) {\n    logger.error(\"stats client build failed\", { cause: err });\n    // surface err.message (includes build output) to the operator\n  } else throw err;\n}","preventionTips":["Run `bun run build.ts` in packages/stats locally before starting the server","Keep dependencies installed and up to date in the workspace","Typecheck client code in CI so build failures surface before runtime"],"tags":["build","bundler","subprocess","cli"],"backgroundTag":"build-script-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}