vercel/next.js · error
Failed to parse source map for ${filename}.
Error message
Failed to parse source map for ${filename}. What it means
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.
Source
Thrown at packages/next/src/server/dev/get-source-map-from-file.ts:66
try {
buffer = dataUriToBuffer(sourceUrl)
} catch (error) {
throw new Error(`Failed to parse source map URL for ${filename}.`, {
cause: error,
})
}
if (buffer.type !== 'application/json') {
throw new Error(
`Unknown source map type for ${filename}: ${buffer.typeFull}.`
)
}
try {
return JSON.parse(buffer.toString())
} catch (error) {
throw new Error(`Failed to parse source map for ${filename}.`, {
cause: error,
})
}
}
const sourceMapFilename = path.resolve(
path.dirname(filename),
decodeURIComponent(sourceUrl)
)
try {
const sourceMapContents = await fs.readFile(sourceMapFilename, 'utf-8')
return JSON.parse(sourceMapContents.toString())
} catch (error) {
throw new Error(`Failed to parse source map ${sourceMapFilename}.`, {
cause: error,
})View on GitHub (pinned to 0ae8c72462)
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.
Example fix
// before (truncated base64 body that fails JSON.parse) //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj // after (regenerated, complete, valid source map) //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==
Defensive patterns
Strategy: validation
Validate before calling
// Decode + validate an inline JSON source map body before use
function validateInlineJsonMap(dataUri: string) {
const idx = dataUri.indexOf(',')
const encoded = dataUri.slice(idx + 1)
const isBase64 = /;base64/.test(dataUri.slice(0, idx))
const text = isBase64 ? Buffer.from(encoded, 'base64').toString('utf8') : decodeURIComponent(encoded)
return JSON.parse(text) // throws on truncated/corrupt JSON, surfaced before Next.js wraps it
} Try / catch
try {
return JSON.parse(buffer.toString())
} catch (cause) {
throw new Error(`Failed to parse source map for ${filename}.`, { cause })
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to read file contents of ${filename}.
- Failed to parse source map URL for ${filename}.
- Unknown source map type for ${filename}: ${buffer.typeFull}.
- Failed to parse source map ${sourceMapFilename}.
- ${sourceURL}: Invalid source map. Only conformant source map
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/7ba850b2d584fa95.
Report an issue: GitHub.