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

{msg}

Error message

{msg}

What it means

The plugin transform failed and the returned PluginError is Deserialize(msg) or Serialize(msg): the plugin could not serialize its transformed AST for the host, or the bytes it produced could not be deserialized, and {msg} is the underlying rkyv/serialization error text. This is the classic host/plugin AST schema mismatch signature.

Source

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

        // 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.
     *
     * Host should appropriately handle if plugin is not compatible to the
     * current runtime.
     */
    #[allow(unreachable_code)]

View on GitHub (pinned to d7d7434666)

Solutions

  1. Pin the plugin's swc_core to the same version the host uses and rebuild the plugin wasm
  2. Confirm with cargo tree which swc_core each side resolved; mismatched minor versions are enough
  3. If versions match, reproduce with a minimal input and report the {msg} payload upstream - it may indicate a genuine serialization bug

Example fix

# before: plugin on old swc_core, host on new
# plugin Cargo.toml
swc_core = "8"

# after
swc_core = "10"  # exactly match the host, then rebuild the wasm
Defensive patterns

Strategy: try-catch

Try / catch

// Rust: distinguish schema-mismatch serialization failures from real plugin bugs
let msg = format!("{e:#}");
if msg.contains("failed to serialize") || msg.contains("failed to deserialize") || msg.contains("Serialize") {
    return Err(anyhow!("plugin/host swc_core version mismatch (serialize/deserialize failed); align versions and rebuild the plugin"));
}

Prevention

When it happens

Trigger: Plugin built with a swc_core whose rkyv-derived AST layout differs from the host's - any serialized-bytes round trip then fails with a deserialize/serialize error inside the plugin; also possible on plugins that mutate the AST into an inconsistent state before serialization.

Common situations: Upgrading @swc/core (host) without rebuilding local plugins, plugins built on nightly swc_core, or publishing a plugin compiled months earlier against current tooling.

Related errors


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