{"record":{"id":"93fc9fec87046b0e","repo":"vercel/next.js","slug":"failed-to-parse-source-map-sourcemapfilename","errorCode":null,"errorMessage":"Failed to parse source map ${sourceMapFilename}.","messagePattern":"Failed to parse source map (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/dev/get-source-map-from-file.ts","lineNumber":82,"sourceCode":"      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    })\n  }\n}\n","sourceCodeStart":64,"sourceCodeEnd":87,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/dev/get-source-map-from-file.ts#L64-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the .map file referenced in the error actually exists next to the compiled file and is readable.","Regenerate output with source maps enabled (delete .next and rebuild) so the .map files are emitted.","Ensure your deploy/copy step includes *.map files alongside the .js chunks.","Validate the .map file contents with a JSON linter; replace it if corrupted."],"exampleFix":"// before: file.js references a missing map\n//# sourceMappingURL=missing.js.map\n\n// after: ensure the map exists and is valid JSON, or drop the reference\n//# sourceMappingURL=file.js.map","handlingStrategy":"validation","validationCode":"import fs from 'fs/promises'\n// Verify an external source map exists and parses before dev/build relies on it\nasync function validateExternalMap(jsFile: string) {\n  const src = await fs.readFile(jsFile, 'utf8')\n  const m = src.match(/\\/\\/#@? ?sourceMappingURL=(\\S+)/)\n  if (!m || m[1].startsWith('data:')) return\n  const mapPath = path.resolve(path.dirname(jsFile), decodeURIComponent(m[1]))\n  await fs.access(mapPath)              // throws if missing/unreadable\n  JSON.parse(await fs.readFile(mapPath, 'utf8')) // throws if not JSON\n}","typeGuard":null,"tryCatchPattern":"try {\n  const raw = await fs.readFile(mapPath, 'utf8')\n  return JSON.parse(raw)\n} catch (cause) {\n  throw new Error(`Failed to parse source map ${mapPath}.`, { cause })\n}","preventionTips":["Ship .map files alongside .js in deployments.","Don't gitignore generated .map files that dev tooling expects.","Keep source-map emission stable across OSes (case-sensitive filenames)."],"tags":["source-maps","dev-server","filesystem"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T01:17:05.418Z"}