vercel/next.js · error

Failed to parse source map ${sourceMapFilename}.

Error message

Failed to parse source map ${sourceMapFilename}.

What it means

Thrown by getSourceMapFromFile when an external source map file (referenced by a relative sourceMappingURL path) cannot be read or JSON.parsed. The code resolves the path relative to the source file's directory, reads it, and JSON.parses it; any read or parse failure is wrapped with this message and the original error as cause. This is the external-file counterpart of the inline-data-URI errors.

Source

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

      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

  1. Verify the .map file referenced in the error actually exists next to the compiled file and is readable.
  2. Regenerate output with source maps enabled (delete .next and rebuild) so the .map files are emitted.
  3. Ensure your deploy/copy step includes *.map files alongside the .js chunks.
  4. Validate the .map file contents with a JSON linter; replace it if corrupted.

Example fix

// before: file.js references a missing map
//# sourceMappingURL=missing.js.map

// after: ensure the map exists and is valid JSON, or drop the reference
//# sourceMappingURL=file.js.map
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs/promises'
// Verify an external source map exists and parses before dev/build relies on it
async function validateExternalMap(jsFile: string) {
  const src = await fs.readFile(jsFile, 'utf8')
  const m = src.match(/\/\/#@? ?sourceMappingURL=(\S+)/)
  if (!m || m[1].startsWith('data:')) return
  const mapPath = path.resolve(path.dirname(jsFile), decodeURIComponent(m[1]))
  await fs.access(mapPath)              // throws if missing/unreadable
  JSON.parse(await fs.readFile(mapPath, 'utf8')) // throws if not JSON
}

Try / catch

try {
  const raw = await fs.readFile(mapPath, 'utf8')
  return JSON.parse(raw)
} catch (cause) {
  throw new Error(`Failed to parse source map ${mapPath}.`, { cause })
}

Prevention

When it happens

Trigger: A file ends with //# sourceMappingURL=foo.js.map but foo.js.map is missing, unreadable, or contains non-JSON content. fs.readFile or JSON.parse throws inside the try block at line 77-80.

Common situations: Source map files were gitignored or deleted from the output directory. A deploy/serve step copied .js but not .js.map. The .map file was corrupted or contains an HTML error page from a misconfigured static server. Path case-sensitivity mismatch on Linux after building on macOS/Windows.

Understand the failure class

Related errors


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