{"record":{"id":"a6ee117e410b879f","repo":"swc-project/swc","slug":"failed-to-serialize-program","errorCode":null,"errorMessage":"failed to serialize program: {}","messagePattern":"failed to serialize program: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/binding_macros/src/wasm.rs","lineNumber":123,"sourceCode":"\n      $crate::wasm::try_with_handler_globals(\n          c.cm.clone(),\n          $opt,\n          |handler| {\n              c.run(|| {\n                  let opts = if opts.is_null() || opts.is_undefined() {\n                      Default::default()\n                  } else {\n                    $crate::wasm::serde_wasm_bindgen::from_value(opts)\n                      .map_err(|e| $crate::wasm::anyhow::anyhow!(\"failed to parse options: {}\", e))?\n                  };\n\n                  let fm = c.cm.new_source_file($crate::wasm::FileName::Anon.into(), String::from(s));\n                  let program = $crate::wasm::anyhow::Context::context(c.minify(fm, handler, &opts, Default::default()), \"failed to minify file\")?;\n\n                  program\n                    .serialize($crate::wasm::compat_serializer().as_ref())\n                    .map_err(|e| $crate::wasm::anyhow::anyhow!(\"failed to serialize program: {}\", e))\n              })\n          },\n      )\n      .map_err(|e| $crate::wasm::convert_err(e, None))\n    }\n  };\n}\n\n/// Currently this relies on existence of minify_sync.\n#[macro_export]\nmacro_rules! build_minify {\n  ($(#[$m:meta])*) => {\n    build_minify!($(#[$m])*, Default::default());\n  };\n  ($(#[$m:meta])*, $opt: expr) => {\n      $(#[$m])*\n      pub fn minify(s: $crate::wasm::js_sys::JsString, opts: $crate::wasm::JsValue) -> $crate::wasm::js_sys::Promise {\n          // TODO: This'll be properly scheduled once wasm have standard backed thread","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/binding_macros/src/wasm.rs#L105-L141","documentation":"Emitted by the build_minify_sync wasm macro after a successful minification when program.serialize(...) (the compatibility serializer that converts the minified AST/result into a JsValue) fails. Parsing and minifying succeeded; only the boundary conversion to a JS value went wrong, which is an internal failure of the binding, not of the input.","triggerScenarios":"Extremely rare: serializer bugs in the wasm binding, or wasm memory exhaustion while materializing the result object for very large outputs; occasionally observed across version transitions when the serializer format changed.","commonSituations":"Minifying unusually large bundles near wasm memory limits; after upgrading the wasm binding where serializer and struct got out of sync (should never happen on a coherent build).","solutions":["Retry with smaller input or fewer output features (no source maps) to rule out memory limits","Upgrade the wasm minify binding - serializer mismatches are fixed in tandem with struct changes","Report to swc with the input and options if it reproduces on latest; include the {e} detail","As a workaround use the napi (@swc/core native) binding which does not cross this serializer path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = minifySync(src, opts);\n} catch (e) {\n  if (String(e).startsWith('failed to serialize program')) {\n    // internal serializer failure: retry smaller / report upstream\n    report(e, { size: src.length, opts });\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Keep inputs and outputs well under the wasm memory ceiling (split large bundles)","Use coherent package versions - never mix a wasm binary from one release with JS glue from another"],"tags":["wasm","minify","serialization","internal-error"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}