{"record":{"id":"b419b84ceb001627","repo":"swc-project/swc","slug":"failed-to-parse-options","errorCode":null,"errorMessage":"failed to parse options: {}","messagePattern":"failed to parse options: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/binding_macros/src/wasm.rs","lineNumber":115,"sourceCode":"    build_minify_sync!($(#[$m])*, Default::default());\n  };\n  ($(#[$m:meta])*, $opt: expr) => {\n    $(#[$m])*\n    pub fn minify_sync(s: $crate::wasm::js_sys::JsString, opts: $crate::wasm::JsValue) -> Result<$crate::wasm::JsValue, $crate::wasm::JsValue> {\n      use serde::Serialize;\n\n      let c = $crate::wasm::compiler();\n\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]","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/binding_macros/src/wasm.rs#L97-L133","documentation":"Generated by the build_minify_sync wasm macro (crates/binding_macros/src/wasm.rs), used by @swc/wasm-minifier / wasm minify entry points. The non-null `opts` JsValue failed serde_wasm_bindgen::from_value deserialization into the minify options struct. null/undefined take the Default path, so this error only occurs when a real value was passed whose shape does not match the Rust struct for the shipped version.","triggerScenarios":"Passing a minify options object with wrong field types (compress: 'true' instead of boolean/object, mangle as a string, format fields nested incorrectly); passing a JSON string instead of an object; using options from a newer/older @swc/core version whose Rust struct in this wasm build does not have those fields/variants (enum value mismatch, e.g. an unknown module config value).","commonSituations":"Version skew between the JS-side typings and the wasm binary after a partial upgrade; copy-pasted options from other bundler docs (terserweboptions style) into swc minify; typos that change the JSON type.","solutions":["Match the MinifyOptions interface shipped with your exact binding version (check its .d.ts); fix wrong-typed fields like compress/mangle booleans","Pass null/undefined (or omit the argument) to run with defaults and confirm the call works, then add options back one by one to find the offending field","Remove fields the Rust struct does not expect rather than relying on ignore behavior for enums/nested objects","Align versions: reinstall the wasm package so the JS typings and the compiled Rust struct match"],"exampleFix":"// before\nminifySync(src, { compress: 'true', mangle: 'true' });\n\n// after\nminifySync(src, { compress: true, mangle: true });","handlingStrategy":"validation","validationCode":"// Validate against the shape before calling the wasm API\nfunction checkMinifyOptions(o) {\n  const errors = [];\n  if ('compress' in o && typeof o.compress !== 'boolean' && typeof o.compress !== 'object')\n    errors.push('compress must be boolean or object');\n  if ('mangle' in o && typeof o.mangle !== 'boolean' && typeof o.mangle !== 'object')\n    errors.push('mangle must be boolean or object');\n  if ('module' in o && typeof o.module !== 'boolean')\n    errors.push('module must be boolean');\n  return errors;\n}\nconst errs = checkMinifyOptions(opts);\nif (errs.length) throw new TypeError errs.join('; ');","typeGuard":"function isMinifyOptions(v) {\n  if (v == null) return true; // null/undefined -> defaults\n  if (typeof v !== 'object' || Array.isArray(v)) return false;\n  const c = v.compress;\n  const m = v.mangle;\n  return (c === undefined || typeof c === 'boolean' || typeof c === 'object') &&\n         (m === undefined || typeof m === 'boolean' || typeof m === 'object');\n}","tryCatchPattern":"try {\n  const out = minifySync(src, opts);\n} catch (e) {\n  if (String(e).startsWith('failed to parse options')) {\n    // e names the offending field via the serde detail; fix the shape and retry\n    throw new TypeError Invalid swc minify options: ${e});\n  }\n  throw e;\n}","preventionTips":["Type the options with the binding's own .d.ts (import type { Options }) so the compiler catches shape drift","Omit the second argument entirely when defaults suffice - null/undefined bypass deserialization","After upgrading, diff the options types changelog; enum values and nested shapes change between majors"],"tags":["wasm","minify","options","serde","deserialization","type-mismatch"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}