{"record":{"id":"6deffd9546996be4","repo":"discordjs/discord.js","slug":"websocketshard-compression-is-set-to-zlib-sync-b","errorCode":null,"errorMessage":"WebSocketShard: Compression is set to zlib-sync, but it is not installed.","messagePattern":"WebSocketShard: Compression is set to zlib-sync, but it is not installed\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/ws/src/ws/WebSocketShard.ts","lineNumber":234,"sourceCode":"\n\t\t\t\t\t\tthis.nativeInflate = inflate;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn('WebSocketShard: Compression is set to native zlib but node:zlib is not available.');\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\n\t\t\t\tcase CompressionMethod.ZlibSync: {\n\t\t\t\t\tconst zlib = await getZlibSync();\n\t\t\t\t\tif (zlib) {\n\t\t\t\t\t\tthis.zLibSyncInflate = new zlib.Inflate({\n\t\t\t\t\t\t\tchunkSize: 65_535,\n\t\t\t\t\t\t\tto: 'string',\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn('WebSocketShard: Compression is set to zlib-sync, but it is not installed.');\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\n\t\t\t\tcase CompressionMethod.ZstdNative: {\n\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});","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/ws/src/ws/WebSocketShard.ts#L216-L252","documentation":"Warning from WebSocketShard.internalConnect when compression is set to zlib-sync but the optional zlib-sync npm package could not be imported. The shard deletes the 'compress' query parameter so the gateway sends uncompressed data instead of crashing. zlib-sync is an optionalDependency of discord.js and must be installed separately in some setups.","triggerScenarios":"Setting WebSocketShardOptions.compression to the zlib-sync method while zlib-sync is not installed or failed to install (e.g. omitted optional dependencies, --no-optional install flags, native build failures for the zlib-sync prebuilt binding).","commonSituations":"npm/yarn/pnpm installed with --ignore-optional or omit=optional in .npmrc; environments without build tooling where zlib-sync's native addon failed to compile; Docker slim images; manually curated dependency trees.","solutions":["Install the package: npm i zlib-sync (it provides prebuilt binaries for common platforms).","Re-enable optional dependencies: remove omit=optional / --ignore-optional and reinstall.","Switch compression to the native zlib method if node:zlib is available in your runtime.","Set compression: null to disable gateway compression entirely."],"exampleFix":"// before\nnpm install discord.js --ignore-optional\n// after\nnpm install zlib-sync\nnpm install discord.js","handlingStrategy":"validation","validationCode":"let zlibSyncAvailable = false;\ntry { await import('zlib-sync'); zlibSyncAvailable = true; } catch {}\nif (compression === 'zlib-sync' && !zlibSyncAvailable) {\n  await import('zlib-sync'); // will throw here with a clear message before connecting\n}","typeGuard":"function isZlibSync(m) { return m != null && typeof m.Inflate === 'function'; }","tryCatchPattern":"try {\n  await import('zlib-sync');\n} catch {\n  console.error('zlib-sync requested but not installed: run `npm i zlib-sync`');\n  process.exit(1);\n}","preventionTips":["Add zlib-sync as a direct dependency if your code references the zlib-sync compression method.","Do not install with --ignore-optional or omit=optional when you rely on zlib-sync.","Verify the native binding builds in your Docker/CI image (needs toolchain if no prebuilt matches).","Fail fast at boot with an explicit check instead of silently running uncompressed."],"tags":["websocket","compression","missing-dependency","zlib-sync","optional-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}