leptos-rs/leptos · critical

Executor::spawn called, but no global 'spawn' function is co

Error message

Executor::spawn called, but no global 'spawn' function is configured.

What it means

This panic comes from any_spawner's no-op spawn placeholder, compiled under the wasm-bindgen target. In a WASM/browser environment there is no default global async executor, so any call to Executor::spawn before one is configured hits this cold function and panics. It is the library's way of saying 'you tried to spawn a task but nobody is driving futures'.

Source

Thrown at any_spawner/src/lib.rs:79

#[cfg(all(not(feature = "wasm-bindgen"), not(debug_assertions)))]
#[cold]
#[inline(never)]
fn no_op_spawn(_: PinnedFuture<()>) {
    #[cfg(debug_assertions)]
    eprintln!(
        "Warning: Executor::spawn called, but no global 'spawn' function is \
         configured (perhaps only spawn_local is supported, e.g., on wasm \
         without threading?)."
    );
}

// Wasm panics if you spawn without an executor
#[cfg(feature = "wasm-bindgen")]
#[cold]
#[inline(never)]
fn no_op_spawn(_: PinnedFuture<()>) {
    panic!(
        "Executor::spawn called, but no global 'spawn' function is configured."
    );
}

#[cfg(not(debug_assertions))]
#[cold]
#[inline(never)]
fn no_op_spawn_local(_: PinnedLocalFuture<()>) {
    panic!(
        "Executor::spawn_local called, but no global 'spawn_local' function \
         is configured."
    );
}

/// Errors that can occur when using the executor.
#[derive(Error, Debug)]
pub enum ExecutorError {
    /// The executor has already been set.

View on GitHub (pinned to 32d20f6c9d)

Solutions

  1. Call any_spawner::spawn::set_executor(Executor::WasmBindgen) (or the equivalent wrapper) early in your wasm entrypoint before any spawn.
  2. If using Leptos, ensure the framework's client-side init (which configures the executor) actually runs on the WASM target.
  3. If you did not intend to run in WASM, check your target/feature flags so the native executor implementation is compiled instead.
  4. Wrap spawn calls behind a guard that no-ops or logs when no executor is configured during tests.

Example fix

// before
fn main() {
    // spawns a resource/effect immediately -> panics in wasm
    leptos::mount::mount_to_body(App);
}
// after
fn main() {
    any_spawner::spawn::set_executor(any_spawner::Executor::WasmBindgen);
    leptos::mount::mount_to_body(App);
}
Defensive patterns

Strategy: validation

Validate before calling

// ensure an executor is installed before spawning (debug guard)
fn assert_executor_ready() {
    // any_spawner exposes no query API; guard by installing it idempotently at startup
    std::sync::Once::new().call_once(|| {
        #[cfg(target_arch = "wasm32")]
        any_spawner::spawn::set_executor(any_spawner::Executor::WasmBindgen);
    });
}

Prevention

When it happens

Trigger: Calling Executor::spawn (directly or via leptos task spawning) in a wasm-bindgen build before assigning a global executor with any_spawner::spawn::set_executor (e.g. executor::spawnLocal / wasm-bindgen-futures based implementation).

Common situations: Rendering a Leptos app in the browser without calling mount + executor setup in wasm-bindgen mode; tests running in wasm without initializing an executor; forgetting the cfg-gated executor init in aCSR/hydrate entrypoint.

Related errors


AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01). Data as JSON: /api/errors/6a793f721ecd959a. Report an issue: GitHub.