Registry / web-framework / koa-compressor

koa-compressor

JSON →
library1.0.3jsnpmunverified

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.

npm install koa-compressor
INSTALL
IMPORT
SIG · KOA-COMPRESSOR
K
koa-compressor
web-frameworkjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compressor
const compressor = require('koa-compressor');
import compressor from 'koa-compressor';
This package is designed for older CommonJS environments and Koa 1.x. Direct ESM `import` is not supported without transpilation.
KoaApp
const Koa = require('koa'); const app = Koa();
import Koa from 'koa'; const app = new Koa();
Koa 1.x uses `Koa()` (not `new Koa()`) and generator functions for middleware. Koa 2.x+ uses `new Koa()` and async/await.

Demonstrates a basic Koa 1.x application using `koa-compressor` middleware to unconditionally gzip compress all responses.

const Koa = require('koa'); const compressor = require('koa-compressor'); const app = Koa(); // Koa 1.x application initialization app.use(compressor()); app.use(function* () { // Koa 1.x middleware uses generator functions (function*) this.type = 'text/plain'; this.body = 'This response will always be gzipped by koa-compressor, regardless of Accept-Encoding headers.'; }); app.listen(3000, () => { console.log('Koa 1.x app with koa-compressor listening on http://localhost:3000'); });
Debug
Known issues
breakingThis 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.
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.
affects: >=2.0.0 of koa
gotcha`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.
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).
affects: >=1.0.0
deprecatedThe `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.
fix
Migrate to `koa-compress` for active maintenance, modern Koa compatibility, broader compression algorithm support, and ongoing security updates.
affects: >=1.0.3
Errors
Common errors & fixes
TypeError: app.use() requires a generator function
`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.
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.
Error: Cannot find module 'koa-compressor' or import 'koa-compressor'
Attempting to use `import` syntax in a CommonJS module or an incorrect path/missing installation.
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.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
koarequiredCore framework, specifically Koa 1.x which used generator functions for middleware.
Agent activity
4 hits · last 30 days
node
4
Resources
koa-compressor — npm install koa-compressor · libregistry