oven-sh/bun · error · Error
${input}: missing default export
Error message
${input}: missing default export What it means
After dynamically importing the input file, the generator reads `mod.default` and expects either a single StringMapSpec object or an array of them. A falsy default export (or none at all) cannot be generated from, so it aborts with the input path in the message.
Source
Thrown at src/codegen/generate-string-map.ts:293
// No `#![allow]` — this is `include!`d, and inner attributes aren't legal
// mid-module. Per-item allows are emitted where needed instead.
return [
`// Generated by src/codegen/generate-string-map.ts from ${rel} — do not edit.`,
``,
...arr.map(s => buildOne(s)),
``,
].join("\n\n");
}
// ── CLI ─────────────────────────────────────────────────────────────────────
if (import.meta.main) {
const [, , input, output] = process.argv;
if (!input || !output) {
throw new Error("usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>");
}
const mod = await import(path.resolve(input));
const specs = mod.default as StringMapSpec<unknown> | StringMapSpec<unknown>[];
if (!specs) throw new Error(`${input}: missing default export`);
writeIfNotChanged(output, generateStringMaps(specs, input));
}
View on GitHub (pinned to 8c5296ac45)
Solutions
- Add `export default` to the spec object or array in the input file.
- If the module intentionally has multiple named specs, default-export them as an array.
Example fix
// before
export const spec = { name: "Map", entries: [] };
// after
const spec = { name: "Map", entries: [] };
export default spec; Defensive patterns
Strategy: type-guard
Validate before calling
const mod = await import(path.resolve(input));
if (!mod.default) throw new Error(`${input}: missing default export`); Type guard
function isStringMapSpec(v: unknown): v is StringMapSpec<unknown> {
return (
typeof v === "object" && v !== null &&
typeof (v as any).name === "string" &&
Array.isArray((v as any).entries)
);
}
const specs = Array.isArray(mod.default) ? mod.default : [mod.default];
if (!specs.every(isStringMapSpec)) throw new Error(`${input}: bad default export shape`); Prevention
- Standardize every .string-map.ts on `export default { ... } satisfies StringMapSpec<T>`.
- Type the spec file against the generator's exported interface so tsc catches shape mistakes before codegen runs.
When it happens
Trigger: The input .string-map.ts exports its spec via a named export (`export const spec = ...`), exports `undefined` conditionally, or is an empty file.
Common situations: Converting an existing spec module to named exports; refactoring so the default export is behind a flag that evaluates falsy.
Related errors
- generate-string-map: duplicate key ${JSON.stringify(k)} in $
- generate-string-map: ${name}: emitCaseInsensitive requires A
- generate-string-map: ${name}: keys ${JSON.stringify(k)} coll
- ${name}: ${entries.length} entries exceed u16 indexOf range
- file did not exist after write: ${outputPath}
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/69aa295dd8cc393d.
Report an issue: GitHub.