{"record":{"id":"870a063029a4b0fe","repo":"parcel-bundler/parcel","slug":"multiple-targets-have-the-same-destination-path","errorCode":null,"errorMessage":"Multiple targets have the same destination path \"${path.relative(path.dirname(pkgFilePath), targetPath)}\"","messagePattern":"Multiple targets have the same destination path \"(.+?)\"","errorType":"exception","errorClass":"ThrowableDiagnostic","httpStatus":null,"severity":"error","filePath":"packages/core/core/src/requests/TargetRequest.js","lineNumber":1461,"sourceCode":"              pkgContents,\n              targetNames.map(t => ({\n                key: `/${t}`,\n                type: 'value',\n              })),\n            ),\n          },\n        ],\n      });\n    }\n  }\n\n  if (diagnostics.length > 0) {\n    // Only add hints to the last diagnostic so it isn't duplicated on each one\n    diagnostics[diagnostics.length - 1].hints = [\n      'Try removing the duplicate targets, or changing the destination paths.',\n    ];\n\n    throw new ThrowableDiagnostic({\n      diagnostic: diagnostics,\n    });\n  }\n}\n\nfunction normalizeSourceMap(options: ParcelOptions, sourceMap) {\n  if (options.defaultTargetOptions.sourceMaps) {\n    if (typeof sourceMap === 'boolean') {\n      return sourceMap ? {} : undefined;\n    } else {\n      return sourceMap ?? {};\n    }\n  } else {\n    return undefined;\n  }\n}\n\nfunction assertTargetsAreNotEntries(","sourceCodeStart":1443,"sourceCodeEnd":1479,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/core/src/requests/TargetRequest.js#L1443-L1479","documentation":"After resolving all targets, TargetRequest verifies that no two targets write to the same output destination path. If duplicates are found, accumulated diagnostics are thrown together with a hint to remove duplicates or change destination paths. The path is shown relative to the package.json directory.","triggerScenarios":"Two or more targets in package.json resolve to the same output file/dir (e.g. `main` and `module` both pointing at `dist/index.js`, or two custom targets sharing a distDir + filename).","commonSituations":"Configuring multiple targets (main/module/browser) without distinct output paths; copy-pasted target entries; refactoring targets without updating dist paths; defaulting multiple targets to the same `dist/` filename.","solutions":["Give each target a distinct output filename or distDir.","Remove the duplicate target.","Use target-specific subdirectories like `dist/cjs/` and `dist/esm/`."],"exampleFix":"// before (package.json)\n{\n  \"main\": \"dist/index.js\",\n  \"module\": \"dist/index.js\"\n}\n\n// after\n{\n  \"main\": \"dist/index.cjs\",\n  \"module\": \"dist/index.mjs\"\n}","handlingStrategy":"validation","validationCode":"import path from 'path';\nfunction assertUniqueTargetPaths(targets, pkgDir) {\n  const seen = new Map();\n  for (const [name, t] of Object.entries(targets || {})) {\n    const p = path.resolve(pkgDir, t.distDir || '', t.distEntry || `${name}.js`);\n    if (seen.has(p)) throw new Error(`Targets ${seen.get(p)} and ${name} share output ${p}`);\n    seen.set(p, name);\n  }\n}","typeGuard":"function targetPathsAreUnique(resolvedPaths) {\n  return new Set(resolvedPaths).size === resolvedPaths.length;\n}","tryCatchPattern":"try { await parcel.run(); } catch (e) {\n  if (/Multiple targets have the same destination path/.test(e.message)) {\n    console.error('Give each target a distinct output path.');\n  } else throw e;\n}","preventionTips":["Use per-format subdirectories (dist/cjs, dist/esm).","Never reuse the same filename across `main`/`module`/custom targets.","Run a pre-build uniqueness check on resolved output paths."],"tags":["parcel","targets","duplicate","output-path","config"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}