{"id":16004,"library":"decompress-response","title":"HTTP Response Decompression Utility","description":"Decompress-response is a focused utility package designed to automatically decompress HTTP `IncomingMessage` streams based on their `Content-Encoding` header. It supports common compression algorithms including `gzip`, `deflate`, `brotli`, and `zstd` (added in v10.0.0). Currently at stable version 10.0.0, released in late 2023, the package follows a release cadence tied to Node.js LTS updates, with major versions often introducing increased Node.js engine requirements. A key differentiator is its straightforward, single-function API that transforms an `http.IncomingMessage` stream into a decompressed stream, making it easy to integrate. It is notably used internally by popular HTTP client libraries like `got` and operates as a pure ECMAScript Module (ESM) package since version 8, requiring modern JavaScript module syntax for usage.","status":"active","version":"10.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/decompress-response","tags":["javascript","decompress","response","http","https","zlib","gzip","zip","deflate","typescript"],"install":[{"cmd":"npm install decompress-response","lang":"bash","label":"npm"},{"cmd":"yarn add decompress-response","lang":"bash","label":"yarn"},{"cmd":"pnpm add decompress-response","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is pure ESM since v8.0.0. CommonJS `require()` syntax will not work. For TypeScript users on v5.x, the correct syntax was `import decompressResponse = require('decompress-response');`, but this was reverted by the ESM-only change in v8.x.","wrong":"const decompressResponse = require('decompress-response');","symbol":"decompressResponse","correct":"import decompressResponse from 'decompress-response';"},{"note":"The `node:` prefix is recommended for built-in Node.js modules for clarity and to avoid conflicts.","symbol":"http","correct":"import http from 'node:http';"},{"note":"Required if you need to manually compress data (e.g., for testing) before passing it to decompress-response. Use the `node:` prefix.","symbol":"zlib","correct":"import zlib from 'node:zlib';"}],"quickstart":{"code":"import http from 'node:http';\nimport zlib from 'node:zlib';\nimport decompressResponse from 'decompress-response';\n\n// Create a simple HTTP server to simulate a compressed response\nconst server = http.createServer((request, serverResponse) => {\n  if (request.url === '/compressed-data') {\n    serverResponse.writeHead(200, {\n      'Content-Type': 'text/plain',\n      'Content-Encoding': 'gzip' // Indicate gzipped content\n    });\n    // Compress the response body\n    zlib.gzip('Hello from decompress-response! This is some example text to be decompressed.', (error, buffer) => {\n      if (error) {\n        console.error('Error gzipping:', error);\n        serverResponse.end('Error gzipping content');\n        return;\n      }\n      serverResponse.end(buffer);\n    });\n  } else {\n    serverResponse.end('Not found');\n  }\n});\n\nserver.listen(3000, () => {\n  console.log('Server listening on http://localhost:3000');\n\n  // Client-side usage: Fetch and decompress the response\n  http.get('http://localhost:3000/compressed-data', response => {\n    console.log('Original response headers:', response.headers);\n\n    let decompressedResponse = decompressResponse(response);\n    let data = '';\n\n    decompressedResponse.on('data', chunk => {\n      data += chunk.toString();\n    });\n\n    decompressedResponse.on('end', () => {\n      console.log('Decompressed data:', data); // Should print 'Hello from decompress-response! ...'\n      server.close(); // Clean up the server after the request\n    });\n\n    decompressedResponse.on('error', error => {\n      console.error('Error during decompression:', error);\n      server.close();\n    });\n  }).on('error', error => {\n    console.error('HTTP GET request error:', error);\n    server.close();\n  });\n});","lang":"javascript","description":"Demonstrates how to set up a basic Node.js server that sends a gzipped response, and then how a client can use `decompress-response` to automatically decompress and consume the HTTP stream."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 20 or later, or pin `decompress-response` to version `^9.0.0` or `<10`.","message":"Version 10.0.0 requires Node.js 20 or newer. Users on older Node.js versions must remain on `decompress-response` v9.x or earlier.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Upgrade your Node.js runtime to version 18 or later, or pin `decompress-response` to version `^8.0.0` or `<9`.","message":"Version 9.0.0 requires Node.js 18 or newer. This continues the trend of aligning major releases with Node.js LTS versions.","severity":"breaking","affected_versions":">=9.0.0 <10.0.0"},{"fix":"Migrate your project to ESM by setting `\"type\": \"module\"` in your `package.json` or by using `.mjs` file extensions, and update all imports to use `import decompressResponse from 'decompress-response';`.","message":"Version 8.0.0 converted the package to pure ECMAScript Module (ESM). CommonJS `require()` statements are no longer supported, leading to `ERR_REQUIRE_ESM` errors.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Upgrade your Node.js runtime to version 12.20.0 or later, or pin `decompress-response` to version `^7.0.0` or `<8`.","message":"Version 8.0.0 increased the minimum Node.js requirement to 12.20.0.","severity":"breaking","affected_versions":">=8.0.0 <9.0.0"},{"fix":"Adjust any logic that inspects the `content-encoding` header on the *returned* stream. The header should be checked on the *original* `response` object if needed.","message":"Version 7.0.0 removed the `content-encoding` header from the response. While primarily a TypeScript type change, if your application relied on inspecting this header after `decompressResponse` was applied, it would break.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"For versions 5.x to 7.x, adjust TypeScript imports. For v8.0.0 and above, revert to the standard `import` statement for ESM compatibility.","message":"Version 5.0.0 introduced a breaking change for TypeScript users, requiring a change from `import decompressResponse from 'decompress-response';` to `import decompressResponse = require('decompress-response');` due to a CommonJS-only export for the TypeScript definition. This was subsequently reverted by the pure ESM transition in v8.0.0.","severity":"breaking","affected_versions":">=5.0.0 <8.0.0"},{"fix":"Upgrade to v9.0.0 or later to ensure the original `http.IncomingMessage` stream is not unintentionally modified. If on an older version, treat the original `response` object as potentially altered after calling `decompressResponse`.","message":"In version 9.0.0, a fix was implemented to prevent `decompress-response` from incorrectly modifying the original response object. Prior versions might have unintended side effects if the original response was used elsewhere after being passed to the function.","severity":"gotcha","affected_versions":"<9.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Convert your consuming file or project to use ECMAScript Modules (ESM) syntax (`import decompressResponse from 'decompress-response';`) and ensure your `package.json` includes `\"type\": \"module\"` or your file uses a `.mjs` extension.","cause":"Attempting to `require()` `decompress-response` in a CommonJS context after upgrading to version 8.0.0 or newer, which is a pure ESM package.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/decompress-response/index.js"},{"fix":"Ensure you are using the correct default import: `import decompressResponse from 'decompress-response';`. For older TypeScript versions (5.x-7.x), check if the `import decompressResponse = require('decompress-response');` syntax is required by your specific setup.","cause":"Incorrect import statement (e.g., `import { decompressResponse } from 'decompress-response';` instead of default import) or a TypeScript configuration mismatch, especially when transitioning between versions.","error":"TypeError: decompressResponse is not a function"},{"fix":"Upgrade your Node.js runtime to version 10 or newer. For `decompress-response` v10.x, Node.js 20 or newer is required.","cause":"Using an older Node.js version (pre-Node.js 10) with `decompress-response` versions that rely on `stream.pipeline` (v5.0.0 and later).","error":"Error: stream.pipeline is not a function"}],"ecosystem":"npm"}