oven-sh/bun · error · BuildError
Failed to load config file: ${path}
Error message
Failed to load config file: ${path} What it means
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.
Source
Thrown at scripts/build.ts:369
const merged = [...bypass].join(",");
process.env.NO_PROXY = merged;
process.env.no_proxy = merged;
}
/**
* Load a ConfigureInput from JSON (for ninja's generator rule replay).
*
* Current format: `{ profile?: string, overrides?: PartialConfig }`.
* Legacy format (pre profile-name persistence): a flat PartialConfig — if we
* see neither `profile` nor `overrides` keys, wrap the whole object as
* overrides so old build dirs still regen.
*/
function loadConfigFile(path: string): ConfigureInput {
let raw: Record<string, unknown>;
try {
raw = JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
} catch (cause) {
throw new BuildError(`Failed to load config file: ${path}`, { cause });
}
if ("profile" in raw || "overrides" in raw) {
return raw as ConfigureInput;
}
// Legacy flat PartialConfig.
return { overrides: raw as PartialConfig };
}
// ───────────────────────────────────────────────────────────────────────────
// CLI arg parsing
// ───────────────────────────────────────────────────────────────────────────
interface CliArgs {
profile: string;
/** PartialConfig overrides from --<field>=<value> flags. */
overrides: PartialConfig;
/** Explicit ninja targets from --target=X. Empty = use defaults. */
ninjaTargets: string[];View on GitHub (pinned to 8c5296ac45)
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
Example fix
# before — broken JSON (trailing comma)
{ "profile": "debug", "overrides": { "asan": false, } }
# after
{ "profile": "debug", "overrides": { "asan": false } } Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from "node:fs";
const raw = readFileSync(path, "utf8");
JSON.parse(raw); // surfaces the exact offset before build.ts wraps it
// legacy flat configs are fine — loadConfigFile wraps them as { overrides: raw } Try / catch
try { loadConfigFile(path); }
catch (e) {
if (/Failed to load config file/.test(e.message)) {
console.error(`${path} is not valid JSON — run: jq . ${path}`);
}
throw e;
} Prevention
- Never hand-edit generated config JSON — pass --flags so it regenerates
- Keep configs in version control so a bad edit is one revert away
When it happens
Trigger: 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.
Common situations: Manually tweaking profile/overrides in the generated JSON and breaking commas; renaming or copying build directories; editors or git operations touching generated files.
Related errors
- Failed to exec ${exe}
- Unknown config field: --${rawKey}
- ${bunProfile} not found — build it first (bun run build:rele
- file did not exist after write: ${outputPath}
- not implemented right
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/524d42a31b0e3bf6.
Report an issue: GitHub.