oven-sh/bun · error · Error
sliceSourceCode truncated
Error message
sliceSourceCode truncated ${moduleList[i]} — likely a regex literal in a position builtin-parser.ts doesn't recognise. Leftover starts: ${processed.rest.slice(0, 80)} What it means
Guard-rail in bundle-modules.ts: after sliceSourceCode processes a builtin module, leftover unparsed text remains. As the adjacent comment explains, builtin-parser.ts only recognizes `/` as a regex start after `[(,=;:{]`, `return`, or `=>`, so a regex literal elsewhere (often with `)` or `}` in its body) desynchronizes the scanner. The message shows the module and the first 80 leftover characters.
Solutions
- Rewrite the regex literal so the `/` appears in a recognized position (e.g. assign it after `=` or inside parentheses)
- Construct the RegExp via `new RegExp(...)` to avoid the literal entirely
- Extend the regex-position heuristic in builtin-parser.ts to recognize the offending context
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/codegen/bundle-modules.ts:148 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/9928d4614dbc9e69.
Report an issue: GitHub.
Appendix: source
Thrown at src/codegen/bundle-modules.ts:148
}
let importStatements: string[] = [];
const processed = sliceSourceCode(
"{" +
input
.replace(
/\bimport(\s*type)?\s*(\{[^}]*\}|(\*\s*as)?\s[a-zA-Z0-9_$]+)\s*from\s*['"][^'"]+['"]/g,
stmt => (importStatements.push(stmt), ""),
)
.replace(/export\s*{\s*}\s*;/g, ""),
true,
x => requireTransformer(x, moduleList[i]),
);
// Guard rail: builtin-parser.ts's regex-position heuristic only recognises
// `/` as regex-start after `[(,=;:{]|return|=>`; a regex whose body has `)`
// or `}` in any other position silently truncates. Fail loudly here.
if (processed.rest.trim() !== "") {
throw new Error(
`sliceSourceCode truncated ${moduleList[i]} — likely a regex literal in a position builtin-parser.ts doesn't recognise. ` +
`Leftover starts: ${processed.rest.slice(0, 80)}`,
);
}
let fileToTranspile = `// GENERATED TEMP FILE - DO NOT EDIT
// Sourced from src/js/${moduleList[i]}
${importStatements.join("\n")}
${processed.result.slice(1).trim()}
;$$EXPORT$$(__intrinsic__exports).$$EXPORT_END$$;
`;
// Attempt to optimize "$exports = ..." to a variableless return
// otherwise, declare $exports so it works.
let exportOptimization = false;
fileToTranspile = fileToTranspile.replace(
/__intrinsic__exports\s*=\s*(.*|.*\{[^\}]*}|.*\([^\)]*\))\n+\s*\$\$EXPORT\$\$\(__intrinsic__exports\).\$\$EXPORT_END\$\$;/,
(_, a) => {View on GitHub (pinned to 8c5296ac45)