babel/babel · error · Error
Decorating two elements with the same name (${desc[key].name
Error message
Decorating two elements with the same name (${desc[key].name}) is not supported yet What it means
Thrown inside applyDecs2311 when two non-field, non-private class elements sharing the same name are both decorated, and they are not a complementary getter/setter pair (the flag^kind check `!== 7` distinguishes a get+set pair from a duplicate). The current decorator runtime does not support decorating two distinct elements with the same name beyond an accessor get/set duo, so it aborts rather than silently dropping a decorator.
Source
Thrown at packages/babel-helpers/src/helpers/applyDecs2311.ts:344
},
};
} else {
desc[key] = decVal;
}
if (!isField) {
setFunctionName(desc[key], name, isMethod ? "" : key);
}
} else if (!isField) {
desc = Object.getOwnPropertyDescriptor(Class, name)!;
}
if (!isField && !isPrivate) {
_ = existingNonFields[+isStatic!][name];
// flag is 1, 3, or 4; kind is 0, 1, 2, 3, or 4
// flag ^ kind is 7 if and only if one of them is 3 and the other one is 4.
if (_ && (_ ^ kind) !== 7) {
throw new Error(
"Decorating two elements with the same name (" +
desc[key].name +
") is not supported yet",
);
}
// We use PROP_KIND.ACCESSOR to mark a name as "fully used":
// either a get/set pair, or a non-getter/setter.
existingNonFields[+isStatic!][name] =
kind < PROP_KIND.GETTER
? PROP_KIND.ACCESSOR
: (kind as PROP_KIND.GETTER | PROP_KIND.SETTER);
}
}
var newValue = Class;
for (var i = decs.length - 1; i >= 0; i -= decoratorsHaveThis ? 2 : 1) {
var dec = assertCallable(decs[i], "A decorator", "be", true) as Function,View on GitHub (pinned to 1eac448147)
Solutions
- Rename one of the colliding decorated elements so names are unique.
- Remove the decorator from the shadowed element if only one should take effect.
- If you intended a getter/setter pair, ensure they are decorated as `accessor`/get+set, not two methods.
- Audit the class for accidental duplicate method declarations introduced during a merge.
Example fix
// before
class C {
@dec handle() {}
@dec handle() {} // duplicate name
}
// after
class C {
@dec handleClick() {}
@dec handleTouch() {}
} Defensive patterns
Strategy: validation
Validate before calling
// Detect duplicate decorated element names at author time
function findDuplicateDecoratedNames(classBody) {
const seen = new Map();
const dups = [];
for (const el of classBody) {
if (el.decorators?.length && el.key) {
if (seen.has(el.key)) dups.push(el.key);
seen.set(el.key, el.kind);
}
}
return dups;
} Prevention
- Use unique names for decorated class elements.
- Run a lint pass that flags duplicate method names within a class body.
- Review merge commits for accidental duplicate method declarations.
When it happens
Trigger: A class declares two methods with the same name (one shadowing the other) and both carry decorators, or a method and a getter with the same name both decorated. The check at line 343 (_ && (_ ^ kind) !== 7) fires for the second decorated element after existingNonFields already recorded the first.
Common situations: Refactoring that accidentally creates duplicate method names while decorators are attached, or merging mixin definitions that collide on a name. Also when a developer expects the second definition to win but both are decorated.
Related errors
- ${hint1} must ${hint2 || "be"} a function${throwUndefined ?
- Attempted to access private element on non-instance
- attempted to call addInitializer after decoration was finish
- accessor decorators must return an object with get, set, or
- Private element is not present on this object
AI-assisted analysis of babel/babel@1eac448147 (2026-08-08).
Data as JSON: /api/errors/c09790f170ad9688.
Report an issue: GitHub.