oven-sh/bun · error · Error
Invalid source map
Error message
Invalid source map
What it means
parseSourceMap() in the bun-error package only accepts version-3 source maps: json.version must be exactly the number 3. Any other value (missing version, the string "3", or another revision) is treated as a map this parser cannot interpret, and stack-frame remapping is aborted.
Source
Thrown at packages/bun-error/sourcemap.ts:9
// Accelerate VLQ decoding with a lookup table
const vlqTable = new Uint8Array(128);
const vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
vlqTable.fill(0xff);
for (let i = 0; i < vlqChars.length; i++) vlqTable[vlqChars.charCodeAt(i)] = i;
export function parseSourceMap(json) {
if (json.version !== 3) {
throw new Error("Invalid source map");
}
if (!(json.sources instanceof Array) || json.sources.some(x => typeof x !== "string")) {
throw new Error("Invalid source map");
}
if (typeof json.mappings !== "string") {
throw new Error("Invalid source map");
}
const { sources, sourcesContent, names, mappings } = json;
const emptyData = new Int32Array(0);
for (let i = 0; i < sources.length; i++) {
sources[i] = {
name: sources[i],
content: (sourcesContent && sourcesContent[i]) || "",
data: emptyData,
dataLength: 0,View on GitHub (pinned to 8c5296ac45)
Solutions
- Ensure the map literally contains "version": 3 as a number
- Confirm you parsed the .map file contents, not the JS file or a URL reference
- Regenerate the map with a standard emitter (Bun bundler, esbuild, tsc, sourcemap-merge tools)
Example fix
// before
parseSourceMap({ sources: ['a.ts'], mappings: '' }); // no version -> throws
// after
parseSourceMap({ version: 3, sources: ['a.ts'], mappings: '' }); Defensive patterns
Strategy: validation
Validate before calling
function looksLikeV3SourceMap(json: unknown): boolean {
return !!json && typeof json === 'object'
&& (json as any).version === 3
&& typeof (json as any).mappings === 'string';
} Type guard
function isV3SourceMap(json: any): json is { version: 3; sources: string[]; mappings: string } {
return json?.version === 3 && typeof json.mappings === 'string';
} Prevention
- Only feed parseSourceMap the JSON.parse of a real .map file
- Regenerate maps with conforming tools instead of hand-editing them
- Keep version as the number 3 when templating/serializing maps
When it happens
Trigger: Calling parseSourceMap(json) where json.version is absent, where version was serialized as the string "3" instead of the number 3, or where a v4/draft map or an unrelated JSON document (package.json, tsconfig) is passed by mistake.
Common situations: Hand-written or minimally-generated maps that omit the version field; pipelines that round-trip JSON through YAML or templating that coerces 3 to "3"; passing the sourceMappingURL string or the wrong file's JSON.
Related errors
- Invalid VLQ data at index ${i}: ${text}
- picsum ${p.id}: ${res.status}
- ${runtime} client exited ${code}${code === null ? " (timed o
- Virtual CSS module not found: ${path}
- Missing sentry_id
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/61e18a5382209dbb.
Report an issue: GitHub.