swc-project/swc · error · anyhow::Error

Failed to convert pointer size to calculate: {msg}

Error message

Failed to convert pointer size to calculate: {msg}

What it means

The plugin transform returned a nonzero result flag, and the deserialized PluginError is SizeInteropFailure: the plugin-side failed to convert a pointer/size pair during memory interop (u32/u64 conversions around guest memory offsets). The {msg} is the plugin's own description of which conversion failed.

Source

Thrown at crates/swc_plugin_runner/src/transform_executor.rs:91

        self.instance.cleanup()?;

        // Construct serialized struct from raw bytes.
        // Since we have finished transformation, it's safe to fetch the data from
        // Arc<Mutex<T>>
        drop(self.instance);
        let transformed_result = Arc::try_unwrap(self.transform_result)
            .map_err(|_| {
                anyhow!("Failed to unwrap Arc: other references to transform_result exist")
            })?
            .into_inner();
        let ret = PluginSerializedBytes::from_bytes(transformed_result);

        let ret = if returned_ptr_result == 0 {
            Ok(ret)
        } else {
            let err: PluginError = ret.deserialize()?.into_inner();
            match err {
                PluginError::SizeInteropFailure(msg) => Err(anyhow!(
                    "Failed to convert pointer size to calculate: {msg}"
                )),
                PluginError::Deserialize(msg) | PluginError::Serialize(msg) => {
                    Err(anyhow!("{msg}"))
                }
                _ => Err(anyhow!(
                    "Unexpected error occurred while running plugin transform"
                )),
            }
        };

        ret
    }

    /**
     * Check compile-time version of AST schema between the plugin and
     * the host. Returns true if it's compatible, false otherwise.
     *

View on GitHub (pinned to d7d7434666)

Solutions

  1. Align the plugin's swc_core version with the host's swc_core version exactly (major.minor at minimum) and rebuild the .wasm
  2. If it persists, test with a smaller input file to rule out guest memory limits on huge ASTs
  3. Read {msg} - it usually names the exact conversion (e.g. TryFromIntError) and points to the offending side

Example fix

# plugin's Cargo.toml before
swc_core = { version = "9", features = [...] }

# after - match the host's swc_core
swc_core = { version = "10", features = [...] }
# then: cargo build --target wasm32-wasi --release
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: verify host/plugin swc_core alignment in CI before shipping
// (parse both versions and compare major.minor)
fn versions_compatible(host: &str, plugin: &str) -> bool {
    let mk = |s: &str| s.split('.').take(2).collect::<Vec<_>>();
    mk(host) == mk(plugin)
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Failed to convert pointer size") => {
        eprintln!("plugin/host interop mismatch - rebuild plugin against swc_core {host_version}");
        return Err(e);
    }
    other => other,
}

Prevention

When it happens

Trigger: Host and plugin disagree on pointer/size width or the serialized AST payload exceeds size limits during write_into_memory_view-style interop; commonly a symptom of the plugin being built against a different swc_core than the host, or a plugin bug in its memory handling.

Common situations: Rebuilding a plugin with a newer swc_core than the embedding host, very large ASTs overflowing guest memory allocations, or hand-rolled plugins that misuse the byte buffer APIs.

Related errors


AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16). Data as JSON: /api/errors/409c249aecadcf1f. Report an issue: GitHub.