{"record":{"id":"524d42a31b0e3bf6","repo":"oven-sh/bun","slug":"failed-to-load-config-file-path","errorCode":null,"errorMessage":"Failed to load config file: ${path}","messagePattern":"Failed to load config file: (.+?)","errorType":"exception","errorClass":"BuildError","httpStatus":null,"severity":"error","filePath":"scripts/build.ts","lineNumber":369,"sourceCode":"  const merged = [...bypass].join(\",\");\n  process.env.NO_PROXY = merged;\n  process.env.no_proxy = merged;\n}\n\n/**\n * Load a ConfigureInput from JSON (for ninja's generator rule replay).\n *\n * Current format: `{ profile?: string, overrides?: PartialConfig }`.\n * Legacy format (pre profile-name persistence): a flat PartialConfig — if we\n * see neither `profile` nor `overrides` keys, wrap the whole object as\n * overrides so old build dirs still regen.\n */\nfunction loadConfigFile(path: string): ConfigureInput {\n  let raw: Record<string, unknown>;\n  try {\n    raw = JSON.parse(readFileSync(path, \"utf8\")) as Record<string, unknown>;\n  } catch (cause) {\n    throw new BuildError(`Failed to load config file: ${path}`, { cause });\n  }\n  if (\"profile\" in raw || \"overrides\" in raw) {\n    return raw as ConfigureInput;\n  }\n  // Legacy flat PartialConfig.\n  return { overrides: raw as PartialConfig };\n}\n\n// ───────────────────────────────────────────────────────────────────────────\n// CLI arg parsing\n// ───────────────────────────────────────────────────────────────────────────\n\ninterface CliArgs {\n  profile: string;\n  /** PartialConfig overrides from --<field>=<value> flags. */\n  overrides: PartialConfig;\n  /** Explicit ninja targets from --target=X. Empty = use defaults. */\n  ninjaTargets: string[];","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/build.ts#L351-L387","documentation":"loadConfigFile() in scripts/build.ts reads and JSON.parses the file passed via --config-file (used by ninja's generator-rule replay of the configure step; legacy flat configs are wrapped as overrides). This BuildError wraps any read or parse failure — the file is missing, unreadable, or not valid JSON.","triggerScenarios":"Hand-editing the generated config JSON and leaving a syntax error; pointing --config-file at a stale path after the build dir moved; a truncated file from an interrupted write; encoding/BOM issues.","commonSituations":"Manually tweaking profile/overrides in the generated JSON and breaking commas; renaming or copying build directories; editors or git operations touching generated files.","solutions":["Validate the JSON: jq . <path> to get the exact syntax error","Fix the reported syntax error","If unsure, delete the config and reconfigure normally — bun bd regenerates it","Confirm the path passed via --config-file exists"],"exampleFix":"# before — broken JSON (trailing comma)\n{ \"profile\": \"debug\", \"overrides\": { \"asan\": false, } }\n\n# after\n{ \"profile\": \"debug\", \"overrides\": { \"asan\": false } }","handlingStrategy":"validation","validationCode":"import { readFileSync } from \"node:fs\";\nconst raw = readFileSync(path, \"utf8\");\nJSON.parse(raw); // surfaces the exact offset before build.ts wraps it\n// legacy flat configs are fine — loadConfigFile wraps them as { overrides: raw }","typeGuard":null,"tryCatchPattern":"try { loadConfigFile(path); }\ncatch (e) {\n  if (/Failed to load config file/.test(e.message)) {\n    console.error(`${path} is not valid JSON — run: jq . ${path}`);\n  }\n  throw e;\n}","preventionTips":["Never hand-edit generated config JSON — pass --flags so it regenerates","Keep configs in version control so a bad edit is one revert away"],"tags":["build","configuration","json","filesystem"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}