swc-project/swc · error

Failed to unwrap Arc: other references to transform_result…

Error message

Failed to unwrap Arc: other references to transform_result exist

What it means

After a plugin transform finishes, the runner drops the plugin instance and calls Arc::try_unwrap on transform_result to take exclusive ownership of the serialized output. If other Arc clones are still alive the unwrap fails and the runner reports this error instead of the plugin result — a reference-counting/lifetime bug in plugin execution, not bad user input.

Solutions

  1. Ensure all other Arc clones (instance handles, cached results) are dropped before unwrapping
  2. Check Arc::strong_count first and clone the inner value when refs remain
  3. Treat as an internal bug: transform_result should not be shared past cleanup
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_plugin_runner/src/transform_executor.rs:81 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/00086a5d0b194134. Report an issue: GitHub.

Appendix: source

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

        let returned_ptr_result = self.instance.transform(
            guest_program_ptr.0,
            guest_program_ptr.1,
            unresolved_mark.as_u32(),
            should_enable_comments_proxy,
        )?;

        self.instance
            .caller()?
            .free(guest_program_ptr.0, guest_program_ptr.1)?;
        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"
                )),

View on GitHub (pinned to 5176682b65)