{"record":{"id":"7ba850b2d584fa95","repo":"vercel/next.js","slug":"failed-to-parse-source-map-for-filename","errorCode":null,"errorMessage":"Failed to parse source map for ${filename}.","messagePattern":"Failed to parse source map for (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/dev/get-source-map-from-file.ts","lineNumber":66,"sourceCode":"\n    try {\n      buffer = dataUriToBuffer(sourceUrl)\n    } catch (error) {\n      throw new Error(`Failed to parse source map URL for ${filename}.`, {\n        cause: error,\n      })\n    }\n\n    if (buffer.type !== 'application/json') {\n      throw new Error(\n        `Unknown source map type for ${filename}: ${buffer.typeFull}.`\n      )\n    }\n\n    try {\n      return JSON.parse(buffer.toString())\n    } catch (error) {\n      throw new Error(`Failed to parse source map for ${filename}.`, {\n        cause: error,\n      })\n    }\n  }\n\n  const sourceMapFilename = path.resolve(\n    path.dirname(filename),\n    decodeURIComponent(sourceUrl)\n  )\n\n  try {\n    const sourceMapContents = await fs.readFile(sourceMapFilename, 'utf-8')\n\n    return JSON.parse(sourceMapContents.toString())\n  } catch (error) {\n    throw new Error(`Failed to parse source map ${sourceMapFilename}.`, {\n      cause: error,\n    })","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/dev/get-source-map-from-file.ts#L48-L84","documentation":"Thrown by getSourceMapFromFile when an inline data: URI source map has the correct application/json MIME type but its body fails JSON.parse. This means the decoded bytes are present but are not valid JSON, so Next.js cannot build a RawSourceMap. The underlying JSON.parse error is attached as cause. It only occurs in dev when the overlay/stack-trace resolver needs the original source for a file whose source map is inlined.","triggerScenarios":"A file's sourceMappingURL=data:application/json;... comment decodes to bytes that are not parseable JSON (truncated, base64-mangled, or hand-edited). JSON.parse throws and is wrapped into this error.","commonSituations":"A base64 inline source map was truncated by a build step, editor, or version-control line-ending normalization. A minifier emitted a malformed inline source map. Manual edits to a compiled file corrupted the trailing data URI body.","solutions":["Delete .next and rebuild to regenerate clean inline source maps.","Inspect the file named in the error; decode its sourceMappingURL data URI and run it through a JSON validator to find the syntax error.","Fix or remove the loader/plugin producing the truncated inline source map.","Fall back to external .map files (sourceMap emission) so the inline body is not the source of corruption."],"exampleFix":"// before (truncated base64 body that fails JSON.parse)\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj\n\n// after (regenerated, complete, valid source map)\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==","handlingStrategy":"validation","validationCode":"// Decode + validate an inline JSON source map body before use\nfunction validateInlineJsonMap(dataUri: string) {\n  const idx = dataUri.indexOf(',')\n  const encoded = dataUri.slice(idx + 1)\n  const isBase64 = /;base64/.test(dataUri.slice(0, idx))\n  const text = isBase64 ? Buffer.from(encoded, 'base64').toString('utf8') : decodeURIComponent(encoded)\n  return JSON.parse(text) // throws on truncated/corrupt JSON, surfaced before Next.js wraps it\n}","typeGuard":null,"tryCatchPattern":"try {\n  return JSON.parse(buffer.toString())\n} catch (cause) {\n  throw new Error(`Failed to parse source map for ${filename}.`, { cause })\n}","preventionTips":["Never edit compiled files' trailing source-map comments by hand.","Add *.map / inline maps to CI checks that JSON-parse them after build.","Rebuild cleanly after loader upgrades."],"tags":["source-maps","dev-server","json"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T01:17:05.418Z"}