swc-project/swc · error · TypeError
Finishers must return a constructor.
Error message
Finishers must return a constructor.
What it means
The #[proc_macro_derive(DeserializeEnum, attributes(tag, encoding))] entry point (which backs swc's tag-aware AST deserialization, usually invoked via #[ast_node]) starts by parsing the token stream into syn::DeriveInput with .expect("failed to parse input as DeriveInput"). Because rustc only invokes derives on valid items, this expect is an internal invariant; a panic here means the macro received tokens that do not form a parseable struct/enum/union.
Source
Thrown at crates/swc_ecma_transforms_base/src/helpers/generated/_decorate.rs:266
return { elements: elements, finisher: finisher };
}
function _disallowProperty(obj, name, objectType) {
if (obj[name] !== undefined) throw new TypeError(objectType + " can't have a ." + name + " property.");
}
function _optionalCallableProperty(obj, name) {
var value = obj[name];
if (value !== undefined && typeof value !== "function") {
throw new TypeError("Expected '" + name + "' to be a function");
}
return value;
}
function _runClassFinishers(constructor, finishers) {
for (var i = 0; i < finishers.length; i++) {
var newConstructor = (0, finishers[i])(constructor);
if (newConstructor !== undefined) {
if (typeof newConstructor !== "function") throw new TypeError("Finishers must return a constructor.");
constructor = newConstructor;
}
}
return constructor;
}
"#,
#[cfg(feature = "inline-helpers")]
deps: super::HelperBitmap::from_bits(0x0000000601a000044000080000000018),
};
#[cfg(feature = "inline-helpers")]
pub fn stmts() -> &'static [swc_ecma_ast::Stmt] {
static STMTS: once_cell::sync::Lazy<Vec<swc_ecma_ast::Stmt>> =
once_cell::sync::Lazy::new(|| super::super::parse(DEF.source, DEF.import_path));
&STMTS
}
View on GitHub (pinned to 5176682b65)
Solutions
- Fix any syntax errors reported on the same item - rustc normally reports those before invoking derives, but interleaved reporting can surface the panic first.
- Expand macros on the item (cargo expand) and verify the result is a well-formed enum definition.
- Ensure you are deriving on a direct enum item, not on a macro invocation or module.
- Report to swc with a reproducible item if the input is plainly valid.
Defensive patterns
Strategy: validation
Prevention
- Derive DeserializeEnum/ast_node directly on enum definitions, not on macro invocations.
- Fix item syntax errors first - a broken item can reach the derive before errors are printed in some nightly builds.
When it happens
Trigger: Annotating an item with #[derive(DeserializeEnum)] (or #[ast_node(...)] which forwards to it) where the item's token stream is not a valid DeriveInput - typically macro-generated items that expand to something other than a plain item, or direct token-level invocation of the proc macro.
Common situations: Rare in practice: nightly/stable parser drift, derive helper attribute misconfiguration, or procedural-macro test tooling calling derive entry points with raw tokens. If you hit it, the more likely culprits are earlier syntax errors in the same item or an incompatible syn version bundled with a re-exported derive.
Related errors
- An element descriptor's .kind property must be either "metho
- An element descriptor's .placement property must be one of "
- A class descriptor's .kind property must be "class", but a d
- ${objectType} can't have a .${name} property.
- Expected '${name}' to be a function
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/1ad825c42e934ae4.
Report an issue: GitHub.