rollup-config-external-dependencies

raw JSON →
3.0.1 verified Mon Apr 27 auth: no javascript

Rollup configuration to automatically externalize all dependencies, peerDependencies, and optionalDependencies from the bundle. v3.0.1 is current, released June 2024. Node >=18.12.0 required, ESM-only since v3. Differentiators: zero-config, respects package.json fields, works with CommonJS and ESM outputs, and supports TypeScript projects out of the box. Releases are infrequent; v3 breaking change was dropping CJS and older Node versions.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Using CommonJS require() on an ESM-only package since v3.0.0.
fix
Use import statement or dynamic import(): import { externalDependencies } from 'rollup-config-external-dependencies' or const { externalDependencies } = await import(...).
error TypeError: externalDependencies is not a function
cause Using the imported value without calling it (not invoking parentheses).
fix
Use plugins: [externalDependencies()] with parentheses.
error RollupError: Could not resolve 'some-package' (commonjs or esm dependency...)
cause An external dependency is not installed or not listed in package.json, but externalization is active.
fix
Ensure the package is installed and listed in dependencies or peerDependencies, or add it to external manually.
breaking Dropped CommonJS support and requires Node >=18.12.0.
fix Migrate config to ES modules (use import syntax) and upgrade Node to 18.12.0 or later.
gotcha Plugin must be called as a function: externalDependencies(), not used directly as externalDependencies.
fix Add parentheses: plugins: [externalDependencies()]
gotcha Externalization includes the package itself if it's listed as a dependency; ensure no unintended externals.
fix Check package.json dependencies/peerDependencies and adjust with options if needed.
npm install rollup-config-external-dependencies
yarn add rollup-config-external-dependencies
pnpm add rollup-config-external-dependencies

Basic Rollup config using externalDependencies to automatically exclude external packages from bundle.

// rollup.config.js
import { externalDependencies } from 'rollup-config-external-dependencies';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm',
  },
  plugins: [
    externalDependencies(),
  ],
};