{"record":{"id":"d0b66308fb74a99d","repo":"wasmerio/wasmer","slug":"zstd-content-encoding-is-not-supported-on-wasm32","errorCode":null,"errorMessage":"zstd content-encoding is not supported on wasm32","messagePattern":"zstd content-encoding is not supported on wasm32","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/wasix/src/runtime/package_loader/builtin_loader.rs","lineNumber":394,"sourceCode":"        let mut reader: Box<dyn Read> = Box::new(std::io::Cursor::new(body));\n        for encoding in encodings.iter().rev() {\n            match encoding.as_str() {\n                \"gzip\" => {\n                    reader = Box::new(flate2::read::GzDecoder::new(reader));\n                }\n                \"zstd\" => {\n                    #[cfg(not(target_arch = \"wasm32\"))]\n                    {\n                        reader = Box::new(\n                            zstd::stream::read::Decoder::new(reader)\n                                .context(\"failed to initialize zstd decoder\")?,\n                        );\n                    }\n                    #[cfg(target_arch = \"wasm32\")]\n                    {\n                        // NOTE: in browsers this code will not be hit because\n                        // the fetch API automatically handles content decoding.\n                        bail!(\"zstd content-encoding is not supported on wasm32\");\n                    }\n                }\n                \"identity\" => {}\n                other => bail!(\"unsupported content-encoding: {other}\"),\n            }\n        }\n\n        let mut decoded = Vec::new();\n        reader\n            .read_to_end(&mut decoded)\n            .context(\"failed to decode response body\")?;\n        Ok(decoded)\n    }\n}\n\nimpl Default for BuiltinPackageLoader {\n    fn default() -> Self {\n        BuiltinPackageLoader::new()","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/runtime/package_loader/builtin_loader.rs#L376-L412","documentation":"builtin_loader's decode_response_body handles Content-Encoding on downloaded package responses. On the wasm32 target (browser/JS runtime) the zstd decompression path is compiled out, so a response encoded with 'zstd' cannot be decoded and the loader bails. In browsers fetch would normally strip the encoding, so hitting this means the response arrived zstd-encoded outside a decoding layer.","triggerScenarios":"Downloading a WASI package whose server responds with Content-Encoding: zstd while compiled to wasm32 (non-browser wasm runtime, or a browser context where the fetch API did not transparently decode, e.g. manual Request with cache/duck-typed fetch).","commonSituations":"Serving pre-compressed .zst assets from a CDN/proxy that sets Content-Encoding: zstd; custom registry/mirror that unconditionally zstd-compresses; running the loader in a worker or non-browser wasm embedder without zstd support.","solutions":["Reconfigure the serving side to not send Content-Encoding: zstd to wasm clients — serve identity encoding or compress with gzip/brotli that the wasm runtime supports","Fix the fetch layer so content decoding happens transparently (browser fetch decompresses automatically; ensure you're using the platform fetch, not a wrapper that exposes raw bytes)","On the server/CDN, gate zstd on Accept-Encoding negotiation and exclude wasm clients that don't advertise zstd support","If you control the loader build, enable a zstd decoder crate behind the wasm32 cfg and handle the encoding instead of bailing"],"exampleFix":"// before: nginx serving zstd to all clients\n// zstd on;  # applies Content-Encoding: zstd unconditionally\n// after: only to clients that accept it (wasm loader doesn't)\nzstd on;\nzstd_accept_encoding \"gzip\"; // or serve identity to non-zstd UAs\n// or client-side: fetch the uncompressed variant\nlet url = format!(\"{prefix}/{pkg}?encoding=identity\");","handlingStrategy":"fallback","validationCode":"// client-side pre-check: probe response headers before decoding the body\nlet resp = fetch_head(url).await?;\nlet enc = resp.headers().get(\"content-encoding\").unwrap_or(\"identity\");\nif enc.eq_ignore_ascii_case(\"zstd\") && is_wasm32() {\n    // request an uncompressed variant instead\n    url = format!(\"{url}?encoding=identity\");\n}","typeGuard":"fn is_decodable_on_wasm32(encoding: &str) -> bool {\n    matches!(\n        encoding.to_ascii_lowercase().as_str(),\n        \"identity\" | \"gzip\" | \"x-gzip\" | \"deflate\" | \"br\"\n    ) // zstd excluded on wasm32\n}","tryCatchPattern":"match loader.download_and_decode(url).await {\n    Ok(pkg) => use_package(pkg),\n    Err(e) if e.to_string().contains(\"zstd content-encoding is not supported on wasm32\") => {\n        // fall back to a mirror/URL that serves identity encoding\n        let alt = format!(\"{url}?encoding=identity\");\n        use_package(loader.download_and_decode(&alt).await?)\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Configure CDNs/proxies to negotiate encoding via Accept-Encoding rather than force-serving zstd","Keep a plain (identity-encoded) mirror of package artifacts for wasm clients","Don't wrap the platform fetch with a decoder-less raw-bytes fetch in browser builds","Track zstd support in the loader for wasm32 and upgrade when it lands"],"tags":["wasm32","zstd","http","content-encoding","package-loader"],"backgroundTag":"unsupported-content-encoding","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}