{"id":17739,"library":"koa-compressor","title":"Koa Compressor","description":"Koa Compressor is a middleware for Koa.js designed to simplify HTTP response compression by *always* applying gzip compression. Unlike more configurable alternatives like `koa-compress`, this package explicitly ignores the `Accept-Encoding` header, does not set a `Vary` header, and lacks the `this.compress` option for manual control. It sets the `Content-Length` header on compressed bodies. The package is currently at version 1.0.3, with its last publish approximately seven years ago, indicating it is no longer actively maintained. This makes it primarily compatible with older Koa 1.x applications which rely on generator-based middleware, and it lacks support for modern Koa 2.x+ async/await middleware patterns or contemporary compression algorithms like Brotli or Zstandard.","status":"abandoned","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/koajs/compressor","tags":["javascript","compression","http","compress","gzip"],"install":[{"cmd":"npm install koa-compressor","lang":"bash","label":"npm"},{"cmd":"yarn add koa-compressor","lang":"bash","label":"yarn"},{"cmd":"pnpm add koa-compressor","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core framework, specifically Koa 1.x which used generator functions for middleware.","package":"koa","optional":false}],"imports":[{"note":"This package is designed for older CommonJS environments and Koa 1.x. Direct ESM `import` is not supported without transpilation.","wrong":"import compressor from 'koa-compressor';","symbol":"compressor","correct":"const compressor = require('koa-compressor');"},{"note":"Koa 1.x uses `Koa()` (not `new Koa()`) and generator functions for middleware. Koa 2.x+ uses `new Koa()` and async/await.","wrong":"import Koa from 'koa'; const app = new Koa();","symbol":"KoaApp","correct":"const Koa = require('koa'); const app = Koa();"}],"quickstart":{"code":"const Koa = require('koa');\nconst compressor = require('koa-compressor');\n\nconst app = Koa(); // Koa 1.x application initialization\n\napp.use(compressor());\n\napp.use(function* () {\n  // Koa 1.x middleware uses generator functions (function*)\n  this.type = 'text/plain';\n  this.body = 'This response will always be gzipped by koa-compressor, regardless of Accept-Encoding headers.';\n});\n\napp.listen(3000, () => {\n  console.log('Koa 1.x app with koa-compressor listening on http://localhost:3000');\n});","lang":"javascript","description":"Demonstrates a basic Koa 1.x application using `koa-compressor` middleware to unconditionally gzip compress all responses."},"warnings":[{"fix":"For Koa 2.x and later, use `koa-compress` (the actively maintained alternative) which supports async/await middleware and offers more configurable compression options, including Brotli and Zstandard. Do not attempt to use `koa-compressor` with modern Koa applications.","message":"This package is fundamentally incompatible with Koa 2.x and later versions. `koa-compressor` was designed for Koa 1.x, which uses generator functions (`function*`) for middleware. Koa 2.x+ transitioned to async/await functions, leading to runtime errors if used directly.","severity":"breaking","affected_versions":">=2.0.0 of koa"},{"fix":"If flexible compression (e.g., Brotli, Deflate), client `Accept-Encoding` negotiation, or proper `Vary` header handling is required, use `koa-compress`. `koa-compressor` is suitable only for very specific use cases where unconditional gzip compression is desired and `Accept-Encoding` can be safely ignored (e.g., SPDY/HTTP/2 with specific client constraints).","message":"`koa-compressor` *always* compresses responses using gzip and intentionally ignores the `Accept-Encoding` header from the client. It also does not set a `Vary` header. This behavior is a core design choice but deviates significantly from standard HTTP compression middleware (`koa-compress`) and can lead to unexpected behavior if clients do not support gzip or if downstream caches expect a `Vary` header.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Migrate to `koa-compress` for active maintenance, modern Koa compatibility, broader compression algorithm support, and ongoing security updates.","message":"The `koa-compressor` package is abandoned, with its last release approximately seven years ago. It no longer receives updates, bug fixes, or security patches, making it a potential security risk due to unpatched vulnerabilities in its dependencies or Node.js compatibility issues.","severity":"deprecated","affected_versions":">=1.0.3"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"This package is not compatible with Koa 2.x+. Downgrade Koa to 1.x (not recommended for new projects) or, preferably, switch to `koa-compress` which is compatible with modern Koa versions and maintained.","cause":"`koa-compressor` is being used with Koa 2.x or later, which expects async/await middleware functions, but `koa-compressor`'s internal middleware is generator-based.","error":"TypeError: app.use() requires a generator function"},{"fix":"Ensure the package is installed (`npm install koa-compressor`). If using Node.js without an ESM setup (which is likely for this older package), use `const compressor = require('koa-compressor');`. For ESM projects, this package is not suitable; use `koa-compress` instead.","cause":"Attempting to use `import` syntax in a CommonJS module or an incorrect path/missing installation.","error":"Error: Cannot find module 'koa-compressor' or import 'koa-compressor'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}