swc-project/swc · error
Should able to convert size
Error message
Should able to convert size
What it means
In PluginTransformState::run, the serialized program length (usize) is converted with try_into() into the i32 size argument for caller.alloc before copying the AST into the plugin's memory. The expect panics when the serialized AST exceeds the i32 range (~2 GiB) - the wasm trampoline cannot express such a size.
Source
Thrown at crates/swc_plugin_runner/src/transform_executor.rs:56
#[cfg(feature = "encoding-impl")]
impl PluginTransformState {
fn run(
mut self,
program: &PluginSerializedBytes,
unresolved_mark: swc_common::Mark,
should_enable_comments_proxy: Option<bool>,
) -> Result<PluginSerializedBytes, Error> {
let should_enable_comments_proxy =
u32::from(should_enable_comments_proxy.unwrap_or_default());
// Copy host's serialized bytes into guest (plugin)'s allocated memory.
let guest_program_ptr = write_into_memory_view(
&mut *self.instance.caller()?,
program,
|caller, serialized_len| {
let serialized_len = serialized_len
.try_into()
.expect("Should able to convert size");
caller.alloc(serialized_len).unwrap_or_else(|_| {
panic!("Should able to allocate memory for the size of {serialized_len}")
})
},
);
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()?;
View on GitHub (pinned to 5176682b65)
Solutions
- Transform per file/module so each serialized program stays well under the limit.
- Exclude enormous generated files (data modules, base64 assets) from plugin transforms.
- If the input legitimately exceeds 2 GiB serialized, split it at the build-tooling level (bundler/CodeSplitting) before SWC.
Defensive patterns
Strategy: validation
Validate before calling
// Enforce per-transform input limits before invoking plugin transforms;
// the serialized AST must stay under the i32 (~2 GiB) trampoline range.
fn assert_single_transform_limit(src: &str) -> anyhow::Result<()> {
if src.len() > 256 * 1024 * 1024 {
anyhow::bail!("file too large ({ } bytes) for plugin transform; split or exclude it", src.len());
}
Ok(())
} Prevention
- Transform file-by-file; never concatenate modules before a plugin pass.
- Route data/asset modules around plugin transforms in your bundler config.
- Add a size guard at the tool boundary so oversized files fail loudly instead of panicking.
When it happens
Trigger: Compiler.process_js (or any path through swc_plugin_runner's transform executor) with experimental.plugins configured and a single program whose serialized AST is over ~2 GiB.
Common situations: Concatenated monolithic bundles or giant generated modules run through a plugin instead of being transformed per module.
Related errors
- Should be able to convert to i32
- Should be serializable
- Should be serializable
- Should be serializable
- Should be able to convert size
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/5283657daa436fcb.
Report an issue: GitHub.