{"record":{"id":"602c7f617bcf6315","repo":"discordjs/discord.js","slug":"websocketshard-compression-is-set-to-native-zstd","errorCode":null,"errorMessage":"WebSocketShard: Compression is set to native zstd but node:zlib is not available or your node version does not support zstd decompression.","messagePattern":"WebSocketShard: Compression is set to native zstd but node:zlib is not available or your node version does not support zstd decompression\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/ws/src/ws/WebSocketShard.ts","lineNumber":260,"sourceCode":"\t\t\t\t\tconst zlib = await getNativeZlib();\n\t\t\t\t\tif (zlib && 'createZstdDecompress' in zlib) {\n\t\t\t\t\t\tthis.inflateBuffer = [];\n\n\t\t\t\t\t\tconst inflate = zlib.createZstdDecompress({\n\t\t\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\t\t}) as nativeZlib.Inflate;\n\n\t\t\t\t\t\tinflate.on('data', (chunk) => {\n\t\t\t\t\t\t\tthis.inflateBuffer.push(chunk);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tinflate.on('error', (error) => {\n\t\t\t\t\t\t\tthis.emit(WebSocketShardEvents.Error, error);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tthis.nativeInflate = inflate;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t'WebSocketShard: Compression is set to native zstd but node:zlib is not available or your node version does not support zstd decompression.',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tparams.delete('compress');\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (this.identifyCompressionEnabled) {\n\t\t\tconst zlib = await getNativeZlib();\n\t\t\tif (!zlib) {\n\t\t\t\tconsole.warn('WebSocketShard: Identify compression is enabled, but node:zlib is not available.');\n\t\t\t\tthis.identifyCompressionEnabled = false;\n\t\t\t}\n\t\t}\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/ws/src/ws/WebSocketShard.ts#L242-L278","documentation":"Warning from WebSocketShard.internalConnect when compression is set to native zstd but either node:zlib is unavailable or the running Node.js version lacks zstd decompression support (zstd was added to node:zlib in Node 23.8+/22.15+). The shard deletes the 'compress' parameter so the gateway sends uncompressed payloads. This prevents a crash from calling a nonexistent zlib.createZstd... API.","triggerScenarios":"Setting WebSocketShardOptions.compression to the native zstd method while running a Node.js version whose zlib has no Zstandard support, or in runtimes where node:zlib cannot be loaded at all.","commonSituations":"Running Node 18/20/22.x (pre-22.15) or any LTS older than the zstd additions; Docker images pinned to older Node; users opting into the newest gateway compression before upgrading Node.","solutions":["Upgrade Node.js to a version with zlib zstd support (Node 23.8+, or 22.15+ with the backport; check zlib/zstd availability).","Fall back to zlib-stream transport compression or zlib-sync until the runtime supports zstd.","Set compression: null to disable compression.","Add an engine/runtime check in CI (e.g. engines.node) so zstd compression is only used on supported Node versions."],"exampleFix":"// before\n\"engines\": { \"node\": \">=18\" }\n// after\n\"engines\": { \"node\": \">=23.8 || >=22.15\" } // zlib zstd support required for CompressionMethod.ZstdNative","handlingStrategy":"fallback","validationCode":"let zstdSupported = false;\ntry {\n  const zlib = await import('node:zlib');\n  zstdSupported = typeof zlib.createZstdDecompress === 'function' || typeof zlib.zstdDecompress === 'function';\n} catch {}\nif (compression === 'zstd-native' && !zstdSupported) {\n  compression = 'zlib-stream'; // graceful fallback\n}","typeGuard":"function supportsZstd(z) { return z != null && (typeof z.createZstdDecompress === 'function' || typeof z.zstdDecompressSync === 'function'); }","tryCatchPattern":"try {\n  const zlib = await import('node:zlib');\n  if (!supportsZstd(zlib)) throw new Error('no zstd');\n} catch {\n  shardOptions.compression = CompressionMethod.ZlibStream; // or null\n}","preventionTips":["Pin Node >=23.8 (or >=22.15) when using native zstd compression.","Encode minimum Node version in engines and verify in CI before enabling zstd.","Prefer zlib-stream/zlib-sync in mixed-fleet deployments where Node versions differ.","Monitor for this warning and treat it as a prompt to upgrade the runtime."],"tags":["websocket","compression","zstd","nodejs-version","runtime-environment"],"backgroundTag":"node-version-unsupported-feature","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}