rollup-plugin-peer-deps-external
raw JSON → 2.2.4 verified Mon Apr 27 auth: no javascript maintenance
Automatically externalizes peerDependencies in Rollup bundles. Current stable version is 2.2.4 (last released October 2020), with a maintenance status. It eliminates manual enumeration of peer dependencies in the `external` config, supports module paths (e.g., `lodash/map`), and includes an optional `includeDependencies` flag. Compared to manually listing externals or using pattern-based approaches, this plugin provides a zero-config solution that reads from package.json. It is widely used in library bundling workflows and has minimal dependencies (only `rollup` as a peer dependency). Release cadence is low; no new features since 2.2.0.
Common errors
error Error: Cannot find module 'rollup-plugin-peer-deps-external' ↓
cause Package not installed or missing from dependencies.
fix
npm install --save-dev rollup-plugin-peer-deps-external
error TypeError: peerDepsExternal is not a function ↓
cause Importing incorrectly (e.g., named import instead of default import).
fix
Use
import peerDepsExternal from 'rollup-plugin-peer-deps-external' (default import). error (!) Plugin peerDepsExternal: Options includeDependencies is deprecated ↓
cause Using deprecated `includeDependencies` option.
fix
Remove
includeDependencies from plugin options. Warnings
deprecated The `includeDependencies` option is deprecated and may be removed in future. ↓
fix Avoid using `includeDependencies`; manually externalize dependencies if needed.
breaking v2.0.0 changed behavior to also externalize module paths (e.g., 'lodash/map') in addition to top-level packages. ↓
fix If you relied on only top-level packages being externalized, update your imports or use a custom external function.
gotcha Plugin must run early in plugin list to externalize peer deps before other plugins (e.g., commonjs) resolve them. ↓
fix Place `peerDepsExternal()` as the first plugin in the `plugins` array.
gotcha Does not handle custom `external` config; if you set both, the plugin may override or conflict. ↓
fix Either use the plugin alone or manually merge external patterns by reading peerDependencies yourself.
Install
npm install rollup-plugin-peer-deps-external yarn add rollup-plugin-peer-deps-external pnpm add rollup-plugin-peer-deps-external Imports
- peerDepsExternal wrong
const peerDepsExternal = require('rollup-plugin-peer-deps-external')correctimport peerDepsExternal from 'rollup-plugin-peer-deps-external'
Quickstart
// rollup.config.js
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'esm'
},
plugins: [
// Should be placed first to ensure peer deps are external before other plugins process them
peerDepsExternal()
]
};