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-exportsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Bundles a JavaScript file with esbuild from CJS to ESM, preserving named exports using the plugin.
Pass `esbuldNamedExportsPlugin()` in the plugins array.
Ensure source files use the exact pattern `module.exports = require('./other')`.Review generated bundle and manually fix if needed.
Use dynamic import in CJS or switch to ESM.
plugins: [esbuldNamedExportsPlugin()]
Add the plugin to the esbuild build configuration.
Ensure format is 'esm' and target is es2017 or higher.