{"id":25339,"library":"esbuild-plugin-extract-helpers","title":"esbuild-plugin-extract-helpers","description":"Esbuild plugin (v0.0.11) that extracts CommonJS helper functions (like those from tslib) into a separate shared file, reducing bundle size when multiple CJS modules are emitted. The plugin hooks into esbuild's build process to deduplicate helper injections that esbuild otherwise inlines into each CJS module. Requires esbuild >=0.19.0 as a peer dependency. Currently a PoC with a focused API surface: configure CJS glob pattern, output directory, and helper filename. Ships TypeScript declarations, targets ESM-only consumption.","status":"active","version":"0.0.10","language":"javascript","source_language":"en","source_url":"https://github.com/antongolub/misc","tags":["javascript","esbuild","plugin","helpers","tslib","cjs","typescript"],"install":[{"cmd":"npm install esbuild-plugin-extract-helpers","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-extract-helpers","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-extract-helpers","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin hooks into esbuild's build lifecycle.","package":"esbuild","optional":false}],"imports":[{"note":"The package is ESM-only; CommonJS require() will fail. Use dynamic import() if necessary.","wrong":"const extractHelpersPlugin = require('esbuild-plugin-extract-helpers')","symbol":"extractHelpersPlugin","correct":"import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'"},{"note":"PluginOptions is a TypeScript type; it is not exported at runtime. The wrong pattern would cause a runtime error if used as a value.","wrong":"const { PluginOptions } = require('esbuild-plugin-extract-helpers')","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'esbuild-plugin-extract-helpers'"},{"note":"The package does not have a default export; only named exports are available. Attempting a default import yields undefined at runtime.","wrong":"import extractHelpersPlugin, { PluginOptions } from 'esbuild-plugin-extract-helpers'","symbol":"default export","correct":"import extractHelpersPlugin from 'esbuild-plugin-extract-helpers'"}],"quickstart":{"code":"import { build } from 'esbuild'\nimport { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'\n\nconst plugin = extractHelpersPlugin({\n  cwd: 'dist',\n  include: /\\.cjs$/,\n  helper: 'helpers.cjs'\n})\n\nawait build({\n  entryPoints: ['src/index.ts'],\n  outdir: 'dist',\n  format: 'cjs',\n  plugins: [plugin],\n  bundle: true\n})","lang":"typescript","description":"Demonstrates basic usage: creates the plugin with custom CJS output directory, file inclusion pattern, and helper filename, then invokes esbuild build with CJS format."},"warnings":[{"fix":"Use Node >=12 or upgrade to a version that supports ESM. Alternatively, use dynamic import() from a CommonJS file: import('esbuild-plugin-extract-helpers').then(m => m.extractHelpersPlugin(...))","message":"The package is ESM-only. Node.js versions that do not support ESM (Node <12) cannot load it.","severity":"breaking","affected_versions":"all"},{"fix":"Adjust the `include` option to match your file patterns. For example, set include: /\\.js$/","message":"The plugin only operates on files that match the `include` regex (default: /./). If your CJS files have a different extension (e.g., .js), they will be ignored.","severity":"gotcha","affected_versions":"all"},{"fix":"Place the extractHelpersPlugin as the first plugin in the plugins array.","message":"The plugin must be added to the esbuild `plugins` array **before** other plugins that may modify output files, otherwise helpers may not be correctly extracted.","severity":"gotcha","affected_versions":"all"},{"fix":"Run `npm install esbuild-plugin-extract-helpers@latest`","message":"Version 0.0.8 introduced a fix that removed a redundant variable. If you are on an older version, update to 0.0.11 to get the latest fixes.","severity":"deprecated","affected_versions":"<0.0.8"}],"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-plugin-extract-helpers` in your project.","cause":"Package is not installed, or installed in a location not in require.resolve() path.","error":"Error: Cannot find module 'esbuild-plugin-extract-helpers'"},{"fix":"Use named import: `import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'`","cause":"Attempted to use a default import when the package only exports named exports.","error":"TypeError: extractHelpersPlugin is not a function"},{"fix":"Set `format: 'cjs'` in the esbuild build options.","cause":"The plugin is designed for CommonJS output; using it with 'esm' or 'iife' format will trigger an error.","error":"Error: The plugin 'extract-helpers' must be used with format 'cjs'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}