rollup-plugin-external-node-modules
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that automatically marks all node_modules packages as external, preventing them from being bundled. Version 1.0.1 is current, stable, and likely low-maintenance. It simplifies Rollup configuration by removing the need to manually list externals. Ships TypeScript types. Key differentiator: zero-config approach compared to manual externals or other plugins like @rollup/plugin-node-resolve combined with externals.
Common errors
error The following Node.js built-in modules were not found: fs, path ↓
cause Plugin externalizes everything in node_modules but not Node.js built-ins if they are not listed as dependencies.
fix
Add Rollup's builtins plugin or manually externalize built-ins: external: ['fs', 'path', ...].
error Error: Could not resolve 'some-package' ↓
cause If 'some-package' is not in node_modules (e.g., a monorepo workspace), the plugin will not externalize it.
fix
Ensure the package is installed or add it to Rollup's 'external' option.
error TypeError: external is not a function ↓
cause Incorrect import; likely used named import instead of default import.
fix
Use import external from 'rollup-plugin-external-node-modules' (default import).
Warnings
gotcha Plugin does not respect Rollup's 'external' option if both are used; run order matters. ↓
fix Do not manually add packages to Rollup's 'external' option when using this plugin, or ensure plugin is listed first.
gotcha Only marks packages under node_modules as external; does not handle deep imports like 'lodash/fp' correctly in all cases. ↓
fix Manually add any specific subpaths to Rollup's 'external' option if needed.
gotcha Plugin does not work with PnP (Plug'n'Play) environments by default; may not detect dependencies correctly. ↓
fix Use with @yarnpkg/plugin-pnp and ensure node_modules is present or handle manually.
Install
npm install rollup-plugin-external-node-modules yarn add rollup-plugin-external-node-modules pnpm add rollup-plugin-external-node-modules Imports
- default wrong
const external = require('rollup-plugin-external-node-modules')correctimport external from 'rollup-plugin-external-node-modules' - externalNodeModules
import externalNodeModules from 'rollup-plugin-external-node-modules' - types wrong
import { RollupPluginExternalNodeModules } from 'rollup-plugin-external-node-modules'correctimport type { RollupPluginExternalNodeModules } from 'rollup-plugin-external-node-modules'
Quickstart
import external from 'rollup-plugin-external-node-modules';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.js',
output: {
dir: 'dist',
format: 'esm',
},
plugins: [external()],
});