{"id":25267,"library":"esbuild-compress","title":"esbuild-compress","description":"esbuild-compress is a plugin for esbuild that compresses embedded data at build time to reduce bundle size, with runtime decompression. Current stable version is 2.2.0. It supports various compression algorithms via configurable compressors, including lazy (async) decompression. Key differentiators: designed specifically for esbuild, supports both sync and async decompression, and works with multiple data formats (JSON, text, etc.). Released under MIT license.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/polyipseity/esbuild-compress","tags":["javascript","compress","compression","esbuild","esbuild-plugin","plugin"],"install":[{"cmd":"npm install esbuild-compress","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-compress","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-compress","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin to function","package":"esbuild","optional":false}],"imports":[{"note":"ESM-only package; CommonJS require is not supported.","wrong":"const esbuildCompress = require('esbuild-compress')","symbol":"default","correct":"import esbuildCompress from 'esbuild-compress'"},{"note":"Package uses default export only; named import will yield undefined.","wrong":"import { esbuildCompress } from 'esbuild-compress'","symbol":"esbuildCompress","correct":"import esbuildCompress from 'esbuild-compress'"},{"note":"Plugin type is from esbuild, not from esbuild-compress.","wrong":"import { Plugin } from 'esbuild-compress'","symbol":"Plugin type (TypeScript)","correct":"import type { Plugin } from 'esbuild'; import esbuildCompress from 'esbuild-compress'"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport esbuildCompress from 'esbuild-compress';\n\nawait build({\n  entryPoints: ['input.js'],\n  outfile: 'output.js',\n  bundle: true,\n  plugins: [\n    esbuildCompress({\n      compressors: [\n        { filter: /\\.json$/, loader: 'json' },\n        { filter: /\\.txt$/, lazy: true, loader: 'text' },\n      ],\n    }),\n  ],\n});","lang":"typescript","description":"Shows basic usage of esbuild-compress plugin with two compressors: one for JSON files (sync) and one for text files (lazy/async)."},"warnings":[{"fix":"Upgrade esbuild to version 0.17.0 or higher.","message":"Requires esbuild >=0.17.0 due to plugin API changes.","severity":"breaking","affected_versions":"<0.17.0"},{"fix":"Use await when importing lazy-compressed modules: const data = await import('./file.txt') (if using dynamic imports) or access the default export and await if using static imports with lazy loader.","message":"The 'lazy' option makes decompression async; importing without await will return a Promise.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Switch to ESM imports (import).","message":"Version 2.x dropped support for CommonJS (require).","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run npm install esbuild-compress --save-dev","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'esbuild-compress'"},{"fix":"Change to 'import esbuildCompress from \"esbuild-compress\"'","cause":"Using named import instead of default import.","error":"TypeError: esbuildCompress is not a function"},{"fix":"Install iltorb if needed: npm install iltorb","cause":"Missing optional dependency for brotli compression.","error":"error: [plugin esbuild-compress] Cannot find module 'iltorb'"},{"fix":"Add \"type\": \"module\" to package.json or use .mjs extension.","cause":"Using ESM syntax in a CommonJS project without type: module.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}