neon-bindings/neon · error
`neon::export` can only be applied to functions, consts…
Error message
`neon::export` can only be applied to functions, consts, statics, and classes (impl blocks).
What it means
The `#[neon::export]` attribute macro only supports a limited set of Rust items: functions, consts, statics, and classes (impl blocks). The `unsupported` function emits this compile error on any other item kind (e.g. modules, enums, type aliases, structs, traits).
Solutions
- Move `#[neon::export]` onto an individual `fn`, `const`, `static`, or an `impl` block (class)
- To export a struct, export an `impl` block for it instead of annotating the struct itself
- Remove the attribute from unsupported items and export individual functions from within them
Example fix
// before
#[neon::export]
struct Config { verbose: bool }
// after
struct Config { verbose: bool }
#[neon::export]
impl Config {
fn new() -> Self { Config { verbose: false } }
} Defensive patterns
Strategy: validation
Validate before calling
// Rust-side habit: verify the annotated item kind // fn / const / static / impl are supported; struct, enum, mod, trait are not
Prevention
- Never put #[neon::export] on struct/enum/mod/trait/type items
- Annotate the impl block for a class, not the struct declaration
- Read the macro docs list of supported items before adding the attribute to unusual items
When it happens
Trigger: Writing `#[neon::export]` above a `mod`, `struct`, `enum`, `trait`, `type`, `use`, or `macro` item; the macro's `export` dispatcher matches the item type, fails all supported arms, and calls `unsupported` with the whole item.
Common situations: Trying to export a whole module or type at once; assuming the macro works like other export systems that accept types; copy-pasting the attribute onto the wrong item when adding native bindings.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Exported functions cannot receive `self`.
- class must be implemented for a type name
- The `neon::main` macro must only be used once
- Cannot combine async method with `#[neon(task)]` attribute
- in classes must take `self` by value, not `&self` or `&mut…
AI-assisted analysis of neon-bindings/neon@38960e4381 (2026-09-13).
Data as JSON: /api/errors/bd7adc550f950592.
Report an issue: GitHub.
Appendix: source
Thrown at crates/neon-macros/src/export/mod.rs:57
}
// Export a class (impl block)
syn::Item::Impl(item) => {
let meta = syn::parse_macro_input!(attr with class::meta::Parser);
class::export(meta, item)
}
// Return an error span for all other types
_ => unsupported(item),
}
}
// Generate an error for unsupported item types
fn unsupported(item: syn::Item) -> proc_macro::TokenStream {
let span = syn::spanned::Spanned::span(&item);
let msg = "`neon::export` can only be applied to functions, consts, statics, and classes (impl blocks).";
let err = syn::Error::new(span, msg);
err.into_compile_error().into()
}
View on GitHub (pinned to 38960e4381)