{"record":{"id":"d972a67048db7e65","repo":"discordjs/discord.js","slug":"websocketshard-identify-compression-is-enabled-b","errorCode":null,"errorMessage":"WebSocketShard: Identify compression is enabled, but node:zlib is not available.","messagePattern":"WebSocketShard: Identify compression is enabled, but node:zlib is not available\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/ws/src/ws/WebSocketShard.ts","lineNumber":274,"sourceCode":"\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\n\t\tconst session = await this.strategy.retrieveSessionInfo(this.id);\n\n\t\tconst url = `${session?.resumeURL ?? this.strategy.options.gatewayInformation.url}?${params.toString()}`;\n\n\t\tthis.debug([`Connecting to ${url}`]);\n\n\t\tconst connection = new WebSocketConstructor(url, [], {\n\t\t\thandshakeTimeout: this.strategy.options.handshakeTimeout ?? undefined,\n\t\t});\n\n\t\tconnection.binaryType = 'arraybuffer';\n\n\t\tconnection.onmessage = (event) => {\n\t\t\tvoid this.onMessage(event.data, event.data instanceof ArrayBuffer);","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/ws/src/ws/WebSocketShard.ts#L256-L292","documentation":"Warning from WebSocketShard.internalConnect when useIdentifyCompression is true but getNativeZlib() returned null, so node:zlib is unavailable to compress the identify payload. The shard sets identifyCompressionEnabled = false and connects without identify compression, trading some bandwidth for compatibility. This mirrors error 341 but scoped to the identify (payload) compression option rather than transport compression.","triggerScenarios":"Setting useIdentifyCompression: true in WebSocketShardOptions/WebSocketManager options in an environment where node:zlib cannot be loaded (custom Node builds without zlib, edge runtimes, broken bundler shims).","commonSituations":"Hosting discord.js in edge/serverless runtimes; minimal Docker images or alpine builds with stripped Node; bundling node:zlib incorrectly; custom Node compiled --without-zlib (shared) library.","solutions":["Run on a standard Node.js build where node:zlib is present.","Fix bundler/runtime config so node:zlib resolves to the real Node builtin (mark as external; use the nodejs runtime).","Set useIdentifyCompression: false explicitly if the environment cannot support it.","Ignore the warning if the automatic fallback to uncompressed identify is acceptable."],"exampleFix":"// before\nnew WebSocketShard({\n  useIdentifyCompression: true, // requires node:zlib\n});\n// after (unsupported runtime)\nnew WebSocketShard({\n  useIdentifyCompression: false,\n});","handlingStrategy":"validation","validationCode":"let nativeZlibAvailable = false;\ntry { await import('node:zlib'); nativeZlibAvailable = true; } catch {}\nif (useIdentifyCompression && !nativeZlibAvailable) {\n  useIdentifyCompression = false; // avoids the warning and silent downgrade\n}","typeGuard":"function hasNativeZlib(z) { return z != null && typeof z.deflateSync === 'function'; }","tryCatchPattern":"try {\n  await import('node:zlib');\n} catch {\n  // no node:zlib in this runtime; disable identify compression up front\n  shardOptions.useIdentifyCompression = false;\n}","preventionTips":["Only enable useIdentifyCompression on standard Node.js runtimes.","Set useIdentifyCompression: false explicitly in edge/serverless deployments.","Run a startup capability check (node:zlib import) before constructing the manager.","Keep identify compression off unless large identify payloads are a measured problem."],"tags":["websocket","compression","identify","nodejs","runtime-environment"],"backgroundTag":"native-module-unavailable","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}