parcel-bundler/parcel · error · ThrowableDiagnostic
Multiple targets have the same destination path "${path.rela
Error message
Multiple targets have the same destination path "${path.relative(path.dirname(pkgFilePath), targetPath)}" What it means
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.
Source
Thrown at packages/core/core/src/requests/TargetRequest.js:1461
pkgContents,
targetNames.map(t => ({
key: `/${t}`,
type: 'value',
})),
),
},
],
});
}
}
if (diagnostics.length > 0) {
// Only add hints to the last diagnostic so it isn't duplicated on each one
diagnostics[diagnostics.length - 1].hints = [
'Try removing the duplicate targets, or changing the destination paths.',
];
throw new ThrowableDiagnostic({
diagnostic: diagnostics,
});
}
}
function normalizeSourceMap(options: ParcelOptions, sourceMap) {
if (options.defaultTargetOptions.sourceMaps) {
if (typeof sourceMap === 'boolean') {
return sourceMap ? {} : undefined;
} else {
return sourceMap ?? {};
}
} else {
return undefined;
}
}
function assertTargetsAreNotEntries(View on GitHub (pinned to 59484858a1)
Solutions
- Give each target a distinct output filename or distDir.
- Remove the duplicate target.
- Use target-specific subdirectories like `dist/cjs/` and `dist/esm/`.
Example fix
// before (package.json)
{
"main": "dist/index.js",
"module": "dist/index.js"
}
// after
{
"main": "dist/index.cjs",
"module": "dist/index.mjs"
} Defensive patterns
Strategy: validation
Validate before calling
import path from 'path';
function assertUniqueTargetPaths(targets, pkgDir) {
const seen = new Map();
for (const [name, t] of Object.entries(targets || {})) {
const p = path.resolve(pkgDir, t.distDir || '', t.distEntry || `${name}.js`);
if (seen.has(p)) throw new Error(`Targets ${seen.get(p)} and ${name} share output ${p}`);
seen.set(p, name);
}
} Type guard
function targetPathsAreUnique(resolvedPaths) {
return new Set(resolvedPaths).size === resolvedPaths.length;
} Try / catch
try { await parcel.run(); } catch (e) {
if (/Multiple targets have the same destination path/.test(e.message)) {
console.error('Give each target a distinct output path.');
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Target "${target.name}" is configured to overwrite entry "${
- Library targets are not supported in serve mode.
- Unexpected output file type ${ext} in target "${targetName}"
- The "global" output format is not supported in the "${target
- Scope hoisting cannot be disabled for library targets.
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/870a063029a4b0fe.
Report an issue: GitHub.