rollup-plugin-auto-named-exports

raw JSON →
1.0.0-beta.3 verified Mon Apr 27 auth: no javascript maintenance

A Rollup plugin that automatically resolves named exports from CommonJS modules to avoid the 'is not exported by module' error. Version 1.0.0-beta.3. Base on rollup-plugin-commonjs, it scans modules and generates namedExports configuration automatically. Release cadence: low, beta stage. Key differentiator: eliminates manual namedExports configuration in rollup-plugin-commonjs. Alternative to manual namedExports or @rollup/plugin-commonjs namedExports. Note: tree-shaking may be affected, use with caution for production builds.

error Error: "[name] is not exported by [module]"
cause CommonJS module does not have named exports that Rollup can statically analyze
fix
Add rollup-plugin-auto-named-exports to automatically resolve named exports.
error TypeError: Cannot read properties of undefined (reading 'namedExports')
cause rollup-plugin-commonjs not included or configured before autoNamedExports()
fix
Ensure commonjs() plugin is added to plugins array before autoNamedExports() as shown in quickstart.
error The plugin "auto-named-exports" does not support Rollup v3+
cause Plugin is not compatible with newer Rollup versions (v3+)
fix
Use alternative solutions like @rollup/plugin-commonjs with namedExports manually or upgrade the plugin if a newer version exists.
breaking Tree-shaking may not work correctly
fix Use manual namedExports if tree-shaking is critical; avoid this plugin in production builds where bundle size matters.
deprecated Package is based on old rollup-plugin-commonjs, not @rollup/plugin-commonjs
fix Migrate to @rollup/plugin-commonjs and consider using its namedExports or other solutions.
gotcha Potential performance impact on build time
fix Use only when necessary; for large projects, specifcy namedExports manually.
gotcha Beta version, may have bugs
fix Test thoroughly in your environment, consider alternatives for production.
npm install rollup-plugin-auto-named-exports
yarn add rollup-plugin-auto-named-exports
pnpm add rollup-plugin-auto-named-exports

Basic setup with rollup-plugin-node-resolve, rollup-plugin-commonjs, and auto-named-exports to automatically resolve named exports.

import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import autoNamedExports from 'rollup-plugin-auto-named-exports';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs'
  },
  plugins: [
    resolve(),
    commonjs({
      namedExports: {
        // no need manual custom
      }
    }),
    autoNamedExports()
  ]
};