swc-project/swc · error · anyhow::Error
failed to serialize transform result: {}
Error message
failed to serialize transform result: {} What it means
Emitted by the build_transform_sync wasm macro (the entry point behind @swc/core's wasm transform) when the successful TransformOutput of process_js cannot be serialized to a JsValue via the compatibility serializer. Transform ran to completion; only the final boundary conversion to JS failed, which indicates an internal binding defect or wasm memory exhaustion - not bad input.
Source
Thrown at crates/binding_macros/src/wasm.rs:404
let comments = $crate::wasm::SingleThreadedComments::default();
$crate::wasm::anyhow::Context::context(
c.process_js_with_custom_pass(
fm,
None,
handler,
&opts,
comments,
$before_pass,
$after_pass,
), "failed to process js file"
)?
}
Err(v) => unsafe { c.process_js(handler, $crate::wasm::serde_wasm_bindgen::from_value(v).expect(""), &opts)? },
};
out
.serialize($crate::wasm::compat_serializer().as_ref())
.map_err(|e| $crate::wasm::anyhow::anyhow!("failed to serialize transform result: {}", e))
})
},
)
.map_err(|e| $crate::wasm::convert_err(e, Some(error_format)))
}
};
}
/// Currently this relies on existence of transform_sync.
#[macro_export]
macro_rules! build_transform {
($(#[$m:meta])*) => {
build_transform!($(#[$m])*, Default::default());
};
($(#[$m:meta])*, $opt: expr) => {
$(#[$m])*
pub fn transform(
s: $crate::wasm::JsValue,View on GitHub (pinned to d7d7434666)
Solutions
- Clean-reinstall the wasm binding (remove node_modules/.cache and lockfile-cached artifacts) to eliminate mixed-version binaries
- Transform without source maps or with smaller inputs to rule out wasm memory limits
- Upgrade to the latest coherent release; these serializer failures are treated as release-blocking bugs
- Report upstream with options and a size-reduced repro, including the {e} detail
Defensive patterns
Strategy: try-catch
Try / catch
try {
const out = transformSync(src, opts);
} catch (e) {
if (String(e).startsWith('failed to serialize transform result')) {
// transform succeeded; only result serialization failed: retry once clean, then report
reportInternal(e, { swcVersion, opts });
}
throw e;
} Prevention
- Clean-reinstall (remove node_modules + lockfile cache) after upgrading @swc/core to avoid mixed-version wasm binaries
- Keep transform outputs and inline source maps modest in size in constrained wasm environments
When it happens
Trigger: Serializer/struct mismatches in a mis-versioned wasm build; memory pressure building the result object for very large outputs (code + sourcemap + metadata); regressions observed around binding version transitions.
Common situations: Large production bundles transformed in browser/wasm toolchains; after upgrading @swc/core where the wasm binary and JS glue got mixed across versions (partial install, cached artifacts).
Related errors
- failed to serialize program: {}
- failed to serialize json: {}
- Failed to serialize output: {e}
- {msg}
- Failed to parse the input
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/1aacf1d4b2f59f84.
Report an issue: GitHub.