vercel/next.js · error

Failed to parse source map URL for ${filename}.

Error message

Failed to parse source map URL for ${filename}.

What it means

Thrown by `getSourceMapFromFile` at line 52 when a `sourceMappingURL` extracted from a file starts with `data:` but `dataUriToBuffer(sourceUrl)` fails to parse it as a valid data URI. The original parse error is attached via `cause`. This only occurs for inline (base64/data-URI) source maps, not external `.map` files.

Source

Thrown at packages/next/src/server/dev/get-source-map-from-file.ts:52

  } catch (error) {
    throw new Error(`Failed to read file contents of ${filename}.`, {
      cause: error,
    })
  }

  const sourceUrl = getSourceMapUrl(fileContents)

  if (!sourceUrl) {
    return undefined
  }

  if (sourceUrl.startsWith('data:')) {
    let buffer: dataUriToBuffer.MimeBuffer

    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,
      })
    }
  }

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Regenerate the affected file's source map by rebuilding (clear `.next` and restart).
  2. If the file comes from a dependency, update or report the malformed source map to the package maintainer.
  3. Temporarily disable source map generation for the offending tool to confirm the inline map is the culprit.
  4. Inspect the `//# sourceMappingURL=data:...` line in the reported file to ensure it is a complete, well-formed data URI.

Example fix

rm -rf .next && pnpm --filter=next dev
Defensive patterns

Strategy: try-catch

Validate before calling

function looksLikeDataUri(u: string): boolean {
  return /^data:[^,]+;base64,/.test(u) || /^data:application\/json[,;]/.test(u);
}
if (sourceUrl.startsWith('data:') && !looksLikeDataUri(sourceUrl)) {
  // skip malformed inline map
}

Type guard

function isValidInlineDataUri(u: string): boolean {
  return u.startsWith('data:') && /\S/.test(u.slice(5));
}

Try / catch

try {
  const map = await getSourceMapFromFile(filename);
} catch (err) {
  if (/Failed to parse source map URL/.test(err.message)) {
    // inline data-URI map is malformed; fall back to no source mapping
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: A `//# sourceMappingURL=data:...` comment that is malformed (truncated, wrong encoding prefix, missing base64 payload); a corrupted build artifact; a hand-edited file with a broken inline source map.

Common situations: Corrupted or truncated inline source maps from a failed/minified build; third-party dependencies shipping malformed data-URI source maps; partial writes during build interruption.

Understand the failure class

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/f13374ae40085320. Report an issue: GitHub.