parcel-bundler/parcel · error · ThrowableDiagnostic
Could not find target with name "${target}"
Error message
Could not find target with name "${target}" What it means
Thrown by TargetRequest.resolve() when a target name in the optionTargets array does not exist in the package's resolved targets map (packageTargets). Each name is checked against packageTargets.has(target); a miss means the name doesn't correspond to any target defined in package.json.
Source
Thrown at packages/core/core/src/requests/TargetRequest.js:236
origin: '@parcel/core',
},
});
}
// Only build the intersection of the exclusive target and option targets.
if (exclusiveTarget != null) {
optionTargets = optionTargets.filter(
target => target === exclusiveTarget,
);
}
// If an array of strings is passed, it's a filter on the resolved package
// targets. Load them, and find the matching targets.
targets = optionTargets
.map(target => {
// null means skipped.
if (!packageTargets.has(target)) {
throw new ThrowableDiagnostic({
diagnostic: {
message: md`Could not find target with name "${target}"`,
origin: '@parcel/core',
},
});
}
return packageTargets.get(target);
})
.filter(Boolean);
} else {
// Otherwise, it's an object map of target descriptors (similar to those
// in package.json). Adapt them to native targets.
targets = Object.entries(optionTargets)
.map(([name, _descriptor]) => {
let {distDir, ...descriptor} = parseDescriptor(
name,
_descriptor,
null,View on GitHub (pinned to 59484858a1)
Solutions
- List the available targets in package.json and use one of those exact names.
- Check for typos in the target name (case-sensitive).
- If you intended to create a new target, add it to the targets section of package.json first.
- In a monorepo, ensure you're referencing a target defined in the correct package.json.
Example fix
// before — package.json targets
{
"targets": {
"main": { "distDir": "dist" }
}
}
// CLI: parcel build --target moden src/index.html
// after — fix the typo
parcel build --target modern src/index.html
// or match exactly:
parcel build --target main src/index.html Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
function validateTargetNamesExist(pkgPath, requestedTargets) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const available = pkg.targets ? Object.keys(pkg.targets) : [];
for (const name of requestedTargets) {
if (!available.includes(name)) {
throw new Error(`Target "${name}" not found. Available: ${available.join(', ') || '(none)'}`);
}
}
} Prevention
- Cross-reference --target names against the targets section in package.json.
- Keep target names stable — avoid renaming them without updating build scripts.
- List available targets in CI logs to catch mismatches early.
When it happens
Trigger: Inside optionTargets.map(target => ...), when packageTargets.has(target) is false. packageTargets comes from resolvePackageTargets(rootDir) which reads the targets section of package.json. The requested name has no matching entry.
Common situations: Passing --target myapp when package.json defines targets named 'main', 'modern', etc.; typo in the target name; target was renamed in package.json but the CLI/option still references the old name; passing a target name from a different package in a monorepo.
Related errors
- Targets option is an empty array
- Missing distDir for target "${name}"
- Failed to parse package.json
- ${path.relative(process.cwd(), source)} does not exist.
- ${path.relative(process.cwd(), source)} is not a file.
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/bd9a722ab7cc0aa3.
Report an issue: GitHub.