swc-project/swc · error · anyhow::Error
Unexpected error occurred while running plugin transform
Error message
Unexpected error occurred while running plugin transform
What it means
Catch-all for plugin transforms that returned a failure flag with a PluginError variant other than SizeInteropFailure/Deserialize/Serialize (the '_' arm of the match in TransformExecutor). The specific error kind was not mapped, so no detail beyond this message survives; the raw error was consumed during matching.
Source
Thrown at crates/swc_plugin_runner/src/transform_executor.rs:97
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)]
pub fn is_transform_schema_compatible(&mut self) -> Result<(), Error> {
#[cfg(any(View on GitHub (pinned to d7d7434666)
Solutions
- Run the plugin host-side in debug mode or enable its logging so the guest's own error output (usually printed before returning) is visible
- Align swc_core versions between host and plugin and rebuild
- Reduce the input to a minimal reproduction and inspect the plugin code path around any expect/unwrap/panic
Defensive patterns
Strategy: try-catch
Try / catch
// Rust: the variant is unmapped - capture context and fail loudly
match result {
Err(e) if e.to_string().contains("Unexpected error occurred while running plugin transform") => {
tracing::error!(input = %file_name, plugin = %plugin_name, "plugin returned unmapped error variant");
return Err(e.context(format!("plugin {plugin_name} failed on {file_name}")));
}
other => other,
} Prevention
- Run plugins once in debug/verbose mode during development so guest-side panics print their own traces
- Keep host and plugin swc_core aligned to avoid new error variants the host cannot name
- Minify the failing input before reporting - maintainers need it
When it happens
Trigger: A plugin returning an uncommon PluginError variant - e.g. an explicit abort/unreachable variant emitted by plugin SDK macros - after instance.transform returned nonzero. Often the tail end of an assert or panic inside the guest converted into a PluginError.
Common situations: Plugin panics or debug_asserts compiled into release wasm, plugin SDK version drift introducing new error variants the host runner does not know, or guest code calling host APIs in the wrong order.
Related errors
- Failed to resolve plugin path: {resolved_path:?}
- Failed to serialize output: {e}
- Failed to unwrap Arc: other references to transform_result e
- Failed to convert pointer size to calculate: {msg}
- {msg}
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/35824eeaa9521790.
Report an issue: GitHub.