{"record":{"id":"61e18a5382209dbb","repo":"oven-sh/bun","slug":"invalid-source-map","errorCode":null,"errorMessage":"Invalid source map","messagePattern":"Invalid source map","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bun-error/sourcemap.ts","lineNumber":9,"sourceCode":"// Accelerate VLQ decoding with a lookup table\nconst vlqTable = new Uint8Array(128);\nconst vlqChars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nvlqTable.fill(0xff);\nfor (let i = 0; i < vlqChars.length; i++) vlqTable[vlqChars.charCodeAt(i)] = i;\n\nexport function parseSourceMap(json) {\n  if (json.version !== 3) {\n    throw new Error(\"Invalid source map\");\n  }\n\n  if (!(json.sources instanceof Array) || json.sources.some(x => typeof x !== \"string\")) {\n    throw new Error(\"Invalid source map\");\n  }\n\n  if (typeof json.mappings !== \"string\") {\n    throw new Error(\"Invalid source map\");\n  }\n\n  const { sources, sourcesContent, names, mappings } = json;\n  const emptyData = new Int32Array(0);\n  for (let i = 0; i < sources.length; i++) {\n    sources[i] = {\n      name: sources[i],\n      content: (sourcesContent && sourcesContent[i]) || \"\",\n      data: emptyData,\n      dataLength: 0,","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/packages/bun-error/sourcemap.ts#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nparseSourceMap({ sources: ['a.ts'], mappings: '' }); // no version -> throws\n\n// after\nparseSourceMap({ version: 3, sources: ['a.ts'], mappings: '' });","handlingStrategy":"validation","validationCode":"function looksLikeV3SourceMap(json: unknown): boolean {\n  return !!json && typeof json === 'object'\n    && (json as any).version === 3\n    && typeof (json as any).mappings === 'string';\n}","typeGuard":"function isV3SourceMap(json: any): json is { version: 3; sources: string[]; mappings: string } {\n  return json?.version === 3 && typeof json.mappings === 'string';\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["sourcemap","parsing","bundler"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}