{"id":18517,"library":"lws-compress","title":"lws-compress","description":"Response compression middleware for the lws (local-web-server) framework, enabling gzip compression for HTTP responses. Current stable version is 3.1.0, compatible with Node.js >=12.17. It adds --compress and --compress.threshold CLI options to lws, with a default compression threshold of 1024 bytes. Published under the lwsjs organization, this middleware is a lightweight, focused solution for local development servers, following the standard.js code style.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/lwsjs/compress","tags":["javascript","lws","lws-middleware"],"install":[{"cmd":"npm install lws-compress","lang":"bash","label":"npm"},{"cmd":"yarn add lws-compress","lang":"bash","label":"yarn"},{"cmd":"pnpm add lws-compress","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: lws-compress is a middleware for the lws framework and requires lws to function.","package":"lws","optional":false}],"imports":[{"note":"Default export since v3.","wrong":"import { compress } from 'lws-compress'","symbol":"compress","correct":"import compress from 'lws-compress'"},{"note":"CommonJS: default export, not named.","wrong":"const { compress } = require('lws-compress')","symbol":"compress","correct":"const compress = require('lws-compress')"},{"note":"Alias for the default export; no named export exists.","symbol":"CompressMiddleware","correct":"import CompressMiddleware from 'lws-compress'"}],"quickstart":{"code":"import lws from 'lws'\nimport compress from 'lws-compress'\n\nconst server = lws({\n  port: 8080,\n  stack: [compress],\n  compress: {\n    threshold: 2048\n  }\n})\nconsole.log('Server running on http://localhost:8080')","lang":"javascript","description":"Starts an lws server with response compression middleware, setting a custom compression threshold of 2048 bytes."},"warnings":[{"fix":"Use ESM imports (import compress from 'lws-compress') or upgrade to Node.js >=12.17 and set type: 'module' in package.json. For CJS, use dynamic import: const compress = (await import('lws-compress')).default.","message":"v3 changed from CommonJS to ESM-only. This breaks require() calls in Node.js versions <12.17 or projects not using ESM.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use default import only: import compress from 'lws-compress'.","message":"v3 removed the named export 'compress'. Previously both default and named exports were available.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure threshold is specified in bytes (e.g., 1024 for 1KB).","message":"Compression threshold is in bytes, not kilobytes. Setting threshold to 1 applies compression to responses >=1 byte, effectively always compressing.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use --compress (or -z) when launching lws, or pass compress: true in lws options.","message":"The --compress option must be explicitly passed to enable compression. Without it, no compression occurs even if the middleware is in the stack.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check lws documentation for compressible content types or implement custom logic.","message":"Compression only applies to responses with content-type that are compressible (e.g., text/html, application/json). Binary files may be skipped.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use default import: import compress from 'lws-compress'","cause":"Using named import { compress } from 'lws-compress' with ESM import syntax, but the package no longer provides that named export (since v3).","error":"SyntaxError: Named export 'compress' not found. The requested module 'lws-compress' is a CommonJS module, which may not support all module.exports as named exports."},{"fix":"Switch to ESM: use import or type: 'module' in package.json. Or use dynamic import: const compress = (await import('lws-compress')).default","cause":"Attempting to use require() with an ESM-only package (v3+).","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/lws-compress/index.js from /path/to/project/app.js not supported."},{"fix":"Ensure you use default import: import compress from 'lws-compress' or const compress = require('lws-compress').default","cause":"Importing the module incorrectly, e.g., using named import when default import is required.","error":"TypeError: compress is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}