swc-project/swc · error
unknown attribute: {attr:?}
Error message
unknown attribute: {attr:?} What it means
Compile-time panic from the `#[ast_node]` proc-macro attribute. The attribute list is parsed as comma-separated idents and only two flags are recognized: `no_clone` (skip deriving Clone) and `no_unknown` (skip the `#[cfg_attr(swc_ast_unknown, non_exhaustive)]` emission). Any other ident panics with `unknown attribute`.
Source
Thrown at crates/ast_node/src/lib.rs:184
// we should use call_site
let mut item = TokenStream::new();
match &input.data {
Data::Enum(data) => {
use syn::parse::Parser;
let attrs = <syn::punctuated::Punctuated<syn::Ident, syn::Token![,]>>::parse_terminated
.parse(args)
.expect("failed to parse #[ast_node]");
let mut has_no_clone = false;
let mut has_no_unknown = false;
for attr in &attrs {
if attr == "no_clone" {
has_no_clone = true;
} else if attr == "no_unknown" {
has_no_unknown = true;
} else {
panic!("unknown attribute: {attr:?}")
}
}
let clone = if !has_no_clone {
Some(quote!(#[derive(Clone)]))
} else {
None
};
let non_exhaustive = if !has_no_unknown {
Some(quote!(#[cfg_attr(swc_ast_unknown, non_exhaustive)]))
} else {
None
};
let mut data = data.clone();
if !has_no_unknown {
let unknown: syn::Variant = if data
.variantsView on GitHub (pinned to 5176682b65)
Solutions
- Remove the unknown ident from the attribute list
- Use exactly `no_clone` or `no_unknown` (or both, comma-separated)
- Check the attribute parsing code in crates/ast_node/src/lib.rs and its tests for the currently accepted flag set
Example fix
// before
#[ast_node(no_visit)]
pub struct Node { pub span: Span }
// after
#[ast_node(no_clone)]
pub struct Node { pub span: Span } Defensive patterns
Strategy: validation
Prevention
- Only pass `no_clone` and `no_unknown` to `#[ast_node]`
- Grep your crate for `#[ast_node(` and review each flag before upgrading swc_ast_node
- Let CI `cargo check` catch typos at expansion time
When it happens
Trigger: Using `#[ast_node(no_visit)]`, `#[ast_node(clone)]`, or a typo like `#[ast_node(no_clne)]`; anything not exactly `no_clone` or `no_unknown` reaches the else arm.
Common situations: Assuming ast_node supports visitor or serde flags it does not; copying flag names from other SWC macros or older versions; IDE autocomplete suggesting nonexistent flags.
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/239db0dc9204072e.
Report an issue: GitHub.