Registry / devops / esbuild-plugin-named-exports

esbuild-plugin-named-exports

JSON →
library3.0.7jsnpmunverified

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(...).

npm install esbuild-plugin-named-exports
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-NAM
E
esbuild-plugin-named-exports
devopsjavascriptv3.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import esbuldNamedExportsPlugin from 'esbuild-plugin-named-exports'
const esbuldNamedExportsPlugin = require('esbuild-plugin-named-exports')
Package is ESM-only; named exports not supported.

Bundles a JavaScript file with esbuild from CJS to ESM, preserving named exports using the plugin.

import esbuild from 'esbuild'; import esbuldNamedExportsPlugin from 'esbuild-plugin-named-exports'; await esbuild.build({ entryPoints: ['./input.js'], bundle: true, outfile: 'output.js', format: 'esm', target: 'es2017', plugins: [esbuldNamedExportsPlugin()], });
Debug
Known issues
gotchaPlugin must be called as a function: `esbuldNamedExportsPlugin()` not just the object.
fix
Pass `esbuldNamedExportsPlugin()` in the plugins array.
affects: >=0.0.0
gotchaPlugin only works when bundling CJS modules that re-export via `module.exports = require(...)`. It does not handle other CJS patterns.
fix
Ensure source files use the exact pattern `module.exports = require('./other')`.
affects: >=0.0.0
gotchaPlugin may incorrectly add named exports for dynamic require() calls or conditional exports.
fix
Review generated bundle and manually fix if needed.
affects: >=0.0.0
breakingIn v3, the package switched to ESM-only, dropping CommonJS support.
fix
Use dynamic import in CJS or switch to ESM.
affects: >=3.0.0
Errors
Common errors & fixes
Error: The plugin "esbuild-plugin-named-exports" is not a function
Passed the plugin object directly instead of calling it as a function.
fix
plugins: [esbuldNamedExportsPlugin()]
export default undefined
Plugin not applied; CJS re-exports lose named exports.
fix
Add the plugin to the esbuild build configuration.
SyntaxError: Unexpected token 'export'
Using plugin with format 'cjs' or target too low.
fix
Ensure format is 'esm' and target is es2017 or higher.
Upgrade
Version history
3.0.7latest on npm
Audit
Dependencies
cjs-module-lexerrequiredUsed to lex CommonJS module exports and detect named exports from require() calls.
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-named-exports — npm install esbuild-plugin-named-exports · libregistry