{"record":{"id":"31244a29c753b6ea","repo":"evanw/esbuild","slug":"duplicate-source-json-stringify-source-found-i","errorCode":null,"errorMessage":"Duplicate source ${JSON.stringify(source)} found in source map","messagePattern":"Duplicate source (.+?) found in source map","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/verify-source-map.js","lineNumber":877,"sourceCode":"        const positions = map.allGeneratedPositionsFor({ source, line: inLine, column: inColumn })\n        recordCheck(positions.length > 0, `expected generated positions: 1, observed generated positions: ${positions.length}`)\n        let found = false\n        for (const { line, column } of positions) {\n          if (line === outLine && column === outColumn) {\n            found = true\n            break\n          }\n        }\n        const expectedPosition = JSON.stringify({ line: outLine, column: outColumn })\n        const observedPositions = JSON.stringify(positions)\n        recordCheck(found, `expected generated position: ${expectedPosition}, observed generated positions: ${observedPositions}`)\n      }\n    }\n\n    const sources = JSON.parse(outCodeMap).sources\n    for (let source of sources) {\n      if (sources.filter(s => s === source).length > 1) {\n        throw new Error(`Duplicate source ${JSON.stringify(source)} found in source map`)\n      }\n    }\n\n    const outMap = await new SourceMapConsumer(outCodeMap)\n    checkMap(outCode, outMap)\n\n    // Check that every generated location has an associated original position.\n    // This only works when not bundling because bundling includes runtime code.\n    if (flags.indexOf('--bundle') < 0) {\n      // The last line doesn't have a source map entry, but that should be ok.\n      const outLines = outCode.trimRight().split('\\n');\n\n      for (let outLine = 0; outLine < outLines.length; outLine++) {\n        if (outLines[outLine].startsWith('#!') || outLines[outLine].startsWith('//')) {\n          // Ignore the hashbang line and the source map comment itself\n          continue;\n        }\n","sourceCodeStart":859,"sourceCodeEnd":895,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/verify-source-map.js#L859-L895","documentation":"Thrown at scripts/verify-source-map.js:877. After parsing the generated source map, the harness iterates `sources` and counts how many times each entry appears; if any source path appears more than once it raises this error. Duplicate source entries make originalPositionFor / sourceContentFor ambiguous, so the map is rejected before deeper checks run.","triggerScenarios":"esbuild emits a source map whose `sources` array lists the same source path twice (or more). This can happen when bundling combines modules that share a resolved path, when path normalization produces colliding strings, or when a plugin returns duplicate source entries.","commonSituations":"A bundling or source-map chaining change causes two input modules to resolve to the same source path in the map; a regression in esbuild's source-map deduplication; or nested source-map merging duplicates an entry.","solutions":["Inspect the generated `.map` file's `sources` array and identify the duplicated path(s).","If esbuild produced the duplicate legitimately (same path twice), treat it as an esbuild bug to fix in source-map generation (deduplicate sources).","If a plugin or path-normalization config caused the collision, normalize the source paths so they are unique."],"exampleFix":"// before (.map sources contains a duplicate)\n{ \"sources\": [\"src/a.js\", \"src/a.js\", \"src/b.js\"] }\n\n// after (esbuild deduplicates; map is unambiguous)\n{ \"sources\": [\"src/a.js\", \"src/b.js\"] }","handlingStrategy":"validation","validationCode":"function hasUniqueSources(mapObj) {\n  const seen = new Set();\n  for (const s of mapObj.sources) {\n    if (seen.has(s)) return s; // duplicate\n    seen.add(s);\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":"try { runSourceMapCheck(); }\ncatch (e) {\n  if (/Duplicate source .* found in source map/.test(e.message)) console.error('esbuild emitted a duplicate entry in .sources:', e.message);\n  throw e;\n}","preventionTips":["Inspect generated `.map` files for duplicate `sources` entries when debugging verification failures.","Treat duplicate sources as an esbuild source-map-generation bug to fix (deduplicate), not a test bug.","Normalize source paths in plugins to avoid accidental collisions."],"tags":["test-harness","source-map","duplicate","verification","bundling"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}