Recursion limit error while expanding `#[wasm_bindgen]` on structs, when wasm-bindgen is not a direct dependency
Author: cocorigonCreated Aug 23, 2026Updated Aug 23, 2026
Describe the bug
When wasm-bindgen is pulled as a transitive dependency (through web-sys for example), and not declared as a direct dependency of the crate, the #[wasm_bindgen] macro reaches a recursion limit error when annotated on any struct. The macro works fine on functions though.
Version
web-sys 0.3.104 wasm-bindgen 0.2.127
Minimal reproduction
src/lib.rs:
use web_sys::wasm_bindgen::{self, prelude::wasm_bindgen};
#[wasm_bindgen]
pub struct MyStruct;Cargo.toml:
[package]
name = "wasm-bindgen-recursion-limit"
edition = "2024"
[dependencies]
web-sys = "0.3.104"Then run cargo build.
Expected behavior
The project builds.
Actual behavior
error: recursion limit reached while expanding `#[wasm_bindgen]`
--> src/lib.rs:3:1
|
3 | #[wasm_bindgen]
| ^^^^^^^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`wasm_bindgen_recursion_limit`)
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `wasm-bindgen-recursion-limit` (lib) due to 1 previous errorSeverity
Annoyance.
Adding wasm-bindgen = "*" to the Cargo dependencies works around the issue.
Source: wasm-bindgen/wasm-bindgen