vercel/next.js · error

Unknown source map type for ${filename}: ${buffer.typeFull}.

Error message

Unknown source map type for ${filename}: ${buffer.typeFull}.

What it means

Thrown by getSourceMapFromFile when an inline (data: URI) source map's MIME type is not 'application/json'. Next.js reads source maps from compiled files to power the dev overlay's original-code view; when the sourceMappingURL is a data: URI, the dataUriToBuffer parser extracts a type, and anything other than application/json is rejected. The original cause is not chained here because there is no thrown error, only an unexpected MIME type. It surfaces during dev-only source map resolution.

Source

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

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

  const sourceMapFilename = path.resolve(
    path.dirname(filename),
    decodeURIComponent(sourceUrl)
  )

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Delete .next and rebuild so the bundler regenerates conformant source maps.
  2. Find the offending file in the error message, inspect its trailing sourceMappingURL data URI, and confirm its MIME is application/json.
  3. Disable or fix the custom loader/plugin that is rewriting source map annotations to a non-JSON content type.
  4. Switch that file to an external .map file (//# sourceMappingURL=foo.js.map) instead of an inline data URI.

Example fix

// before
//# sourceMappingURL=data:text/plain;base64,eyJ2ZXJzaW9uIjozfQ==

// after
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==
Defensive patterns

Strategy: validation

Validate before calling

// Validate an inline data: source map before relying on it
const DATA_URI_RE = /^data:([^;,]+)?(;base64)?,(.*)$/
function assertInlineSourceMapOk(comment: string) {
  const m = comment.match(DATA_URI_RE)
  if (!m) return
  const mime = (m[1] || '').toLowerCase()
  if (mime && mime !== 'application/json') {
    throw new Error(`sourceMappingURL must be application/json, got ${mime}`)
  }
  const body = m[2] ? Buffer.from(m[3], 'base64').toString('utf8') : decodeURIComponent(m[3])
  JSON.parse(body) // throws early if not JSON
}
// run in a build post-step over your compiled files' trailing comments

Type guard

// Narrow a raw object to a V3 source-map-shaped payload
function isRawSourceMap(v: unknown): v is { version: number; sources?: unknown[]; mappings?: string } {
  return typeof v === 'object' && v !== null && 'version' in v
}

Try / catch

try {
  const map = await getSourceMapFromFile(filename)
} catch (e) {
  // non-fatal in dev overlay: degrade to compiled source
  console.warn('source map unavailable for', filename, (e as Error).message)
}

Prevention

When it happens

Trigger: A compiled chunk contains a sourceMappingURL comment whose data: URI uses a non-JSON MIME type (e.g. data:text/plain;base64,... or data:application/octet-stream;...). Triggered when the dev server/overlay tries to read the source map for that file via getSourceMapFromFile.

Common situations: A custom SWC/babel/loader plugin or post-processing step emits inline source maps with an unusual content type. Manually-authored sourceMappingURL data URIs. Corruption of the sourceMappingURL annotation by a CDN or minifier that re-encodes the data URI.

Related errors


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