evanw/esbuild · error · Error
Duplicate source ${JSON.stringify(source)} found in source m
Error message
Duplicate source ${JSON.stringify(source)} found in source map What it means
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.
Source
Thrown at scripts/verify-source-map.js:877
const positions = map.allGeneratedPositionsFor({ source, line: inLine, column: inColumn })
recordCheck(positions.length > 0, `expected generated positions: 1, observed generated positions: ${positions.length}`)
let found = false
for (const { line, column } of positions) {
if (line === outLine && column === outColumn) {
found = true
break
}
}
const expectedPosition = JSON.stringify({ line: outLine, column: outColumn })
const observedPositions = JSON.stringify(positions)
recordCheck(found, `expected generated position: ${expectedPosition}, observed generated positions: ${observedPositions}`)
}
}
const sources = JSON.parse(outCodeMap).sources
for (let source of sources) {
if (sources.filter(s => s === source).length > 1) {
throw new Error(`Duplicate source ${JSON.stringify(source)} found in source map`)
}
}
const outMap = await new SourceMapConsumer(outCodeMap)
checkMap(outCode, outMap)
// Check that every generated location has an associated original position.
// This only works when not bundling because bundling includes runtime code.
if (flags.indexOf('--bundle') < 0) {
// The last line doesn't have a source map entry, but that should be ok.
const outLines = outCode.trimRight().split('\n');
for (let outLine = 0; outLine < outLines.length; outLine++) {
if (outLines[outLine].startsWith('#!') || outLines[outLine].startsWith('//')) {
// Ignore the hashbang line and the source map comment itself
continue;
}
View on GitHub (pinned to f6058f8364)
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.
Example fix
// before (.map sources contains a duplicate)
{ "sources": ["src/a.js", "src/a.js", "src/b.js"] }
// after (esbuild deduplicates; map is unambiguous)
{ "sources": ["src/a.js", "src/b.js"] } Defensive patterns
Strategy: validation
Validate before calling
function hasUniqueSources(mapObj) {
const seen = new Set();
for (const s of mapObj.sources) {
if (seen.has(s)) return s; // duplicate
seen.add(s);
}
return null;
} Try / catch
try { runSourceMapCheck(); }
catch (e) {
if (/Duplicate source .* found in source map/.test(e.message)) console.error('esbuild emitted a duplicate entry in .sources:', e.message);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to find "${id}" in output
- Got null for source content for "${source}"
- Failed to find "${id}" in input
- Duplicated test name "${name}" in ${file}
- The esbuild JavaScript API cannot be bundled. Please mark th
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/31244a29c753b6ea.
Report an issue: GitHub.