{"record":{"id":"da3f335b9c9e8042","repo":"swc-project/swc","slug":"should-able-to-be-deserialized-into-string","errorCode":null,"errorMessage":"Should able to be deserialized into string","messagePattern":"Should able to be deserialized into string","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/swc_plugin_runner/src/imported_fn/handler.rs","lineNumber":45,"sourceCode":"            );\n            builder.emit();\n        })\n    }\n}\n\npub fn emit_output(\n    caller: &mut dyn runtime::Caller<'_>,\n    _env: &BaseHostEnvironment,\n    output_ptr: i32,\n    output_len: i32,\n) {\n    let mut output_bytes = Vec::new();\n    copy_bytes_into_host(caller, output_ptr, output_len, &mut output_bytes);\n    let serialized = PluginSerializedBytes::from_bytes(output_bytes);\n    let output = PluginSerializedBytes::deserialize::<swc_common::plugin::emit::PluginEmitOutput>(\n        &serialized,\n    )\n    .expect(\"Should able to be deserialized into string\");\n\n    experimental_emit(output.0.key, output.0.value);\n}\n","sourceCodeStart":27,"sourceCodeEnd":49,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_plugin_runner/src/imported_fn/handler.rs#L27-L49","documentation":"Host-side handler for a wasm plugin's `emit` call in swc_plugin_runner. It copies bytes from the plugin's linear memory and decodes them as versioned CBOR into `PluginEmitOutput`; when decoding fails, the `.expect(...)` panics. The bytes were encoded by the guest using its own swc_core serialization code, so this panic almost always means the plugin was built against a swc_core whose wire schema differs from the host runner's, or the guest wrote garbage/incorrect length.","triggerScenarios":"A swc wasm plugin calls the emit host import while its guest bindings (swc_core version) do not match the swc_plugin_runner version embedded in the installed @swc/core; or the plugin returns malformed output_ptr/output_len.","commonSituations":"Upgrading @swc/core without rebuilding/reinstalling third-party plugins; plugins built from source with a stale Cargo.lock pinning an older swc_core; mixing plugin builds targeting wasm32-wasi with an incompatible host; custom plugins in a monorepo drifting from the app's @swc_core version.","solutions":["Rebuild the plugin against the exact swc_core version shipped in your @swc/core release and redeploy","Upgrade @swc/core and all swc plugins together in one coordinated change (check each plugin's peerDependencies)","Temporarily disable plugins one by one to confirm which one emits the incompatible bytes","If versions provably match, open an issue on swc-project/swc with the plugin wasm, @swc/core version, and a minimal repro"],"exampleFix":"# before\n# @swc/core@1.3.100 (embeds swc_core X) + plugin built against swc_core X-3\n\n# after\n# in the plugin crate:\ncargo update -p swc_core --precise <version matching @swc/core 1.3.100>\ncargo build-wasi --release && cp target/wasm32-wasi/release/*.wasm ./","handlingStrategy":"validation","validationCode":"// before loading plugins, verify the host runner can serve them\nconst semver = require('semver');\nconst coreVersion = require('@swc/core/package.json').version;\nfor (const [name] of swcConfig.jsc.experimental.plugins) {\n  const peer = require(`${name}/package.json`).peerDependencies?.['@swc/core'];\n  if (peer && !semver.satisfies(coreVersion, peer)) {\n    throw new Error(`${name} requires @swc/core ${peer}, host has ${coreVersion}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"// Rust hosts embedding swc_plugin_runner can contain the panic:\nlet out = std::panic::catch_unwind(AssertUnwindSafe(|| transform_with_plugins()))\n    .map_err(|_| anyhow::anyhow!(\"plugin emit output failed to decode; rebuild plugin against the host swc_core\"));\n// Node users: run plugin-enabled transforms in a worker/child process so a native panic cannot take down the main process","preventionTips":["Treat @swc/core and swc plugin versions as one unit in the lockfile","In-house plugins: CI job that rebuilds wasm against the exact swc_core of the app's @swc/core","Pin exact versions (no ^ ranges) for @swc/core when plugins are enabled"],"tags":["plugin","wasm","cbor","deserialization","version-mismatch","panic"],"backgroundTag":"plugin-host-version-mismatch","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}