{"id":25375,"library":"esbuild-plugin-named-exports","title":"esbuild-plugin-named-exports","description":"An esbuild plugin (v3.0.7, infrequent releases) that rewrites CommonJS re-exports to preserve named exports when bundling CJS to ESM. It uses cjs-module-lexer to detect all named exports and emits explicit named export statements, preventing the common issue where only a default export appears. Unlike manual conversion or other CJS→ESM tools, this plugin automates the re-export of named exports for packages that re-export via module.exports = require(...).","status":"active","version":"3.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/forthealllight/esbuild-plugin-named-exports","tags":["javascript","esbuild","reexport","named","export"],"install":[{"cmd":"npm install esbuild-plugin-named-exports","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-named-exports","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-named-exports","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to lex CommonJS module exports and detect named exports from require() calls.","package":"cjs-module-lexer","optional":false}],"imports":[{"note":"Package is ESM-only; named exports not supported.","wrong":"const esbuldNamedExportsPlugin = require('esbuild-plugin-named-exports')","symbol":"default","correct":"import esbuldNamedExportsPlugin from 'esbuild-plugin-named-exports'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport esbuldNamedExportsPlugin from 'esbuild-plugin-named-exports';\n\nawait esbuild.build({\n  entryPoints: ['./input.js'],\n  bundle: true,\n  outfile: 'output.js',\n  format: 'esm',\n  target: 'es2017',\n  plugins: [esbuldNamedExportsPlugin()],\n});","lang":"javascript","description":"Bundles a JavaScript file with esbuild from CJS to ESM, preserving named exports using the plugin."},"warnings":[{"fix":"Pass `esbuldNamedExportsPlugin()` in the plugins array.","message":"Plugin must be called as a function: `esbuldNamedExportsPlugin()` not just the object.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure source files use the exact pattern `module.exports = require('./other')`.","message":"Plugin only works when bundling CJS modules that re-export via `module.exports = require(...)`. It does not handle other CJS patterns.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Review generated bundle and manually fix if needed.","message":"Plugin may incorrectly add named exports for dynamic require() calls or conditional exports.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use dynamic import in CJS or switch to ESM.","message":"In v3, the package switched to ESM-only, dropping CommonJS support.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"plugins: [esbuldNamedExportsPlugin()]","cause":"Passed the plugin object directly instead of calling it as a function.","error":"Error: The plugin \"esbuild-plugin-named-exports\" is not a function"},{"fix":"Add the plugin to the esbuild build configuration.","cause":"Plugin not applied; CJS re-exports lose named exports.","error":"export default undefined"},{"fix":"Ensure format is 'esm' and target is es2017 or higher.","cause":"Using plugin with format 'cjs' or target too low.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}