rollup-plugin-deps-external
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript
Rollup plugin (v0.2.1) that automatically externalizes dependencies listed in package.json (dependencies, peerDependencies, and Node.js builtins). It simplifies the common task of excluding npm packages from the bundle, reducing bundle size and avoiding duplication. Most code is borrowed from rollup-plugin-auto-external but offers a slightly different API. Its defaults externalize builtins, dependencies, and peerDependencies. The last release was 0.2.0 with 0.2.1 as a patch. No known security issues. It integrates seamlessly with an existing Rollup external function.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. ↓
cause Using CommonJS require to load an ESM-only package.
fix
Convert your config to ESM (use .mjs or "type": "module" in package.json) and use import.
error TypeError: (0 , _rollupPluginDepsExternal.default) is not a function ↓
cause Named import ({ depsExternal }) instead of default import.
fix
Change import statement to: import depsExternal from 'rollup-plugin-deps-external'
error Could not resolve import: some-package (imported by src/index.js). ↓
cause The package is not in package.json (e.g., a devDependency) but the plugin does not externalize it.
fix
Add the package to dependencies or peerDependencies, or use a different externalization strategy.
Warnings
gotcha The package is ESM-only and cannot be used with CommonJS require. ↓
fix Ensure your project is ESM ("type": "module" in package.json) or use a dynamic import.
gotcha The plugin uses a default export. Attempting named import will result in undefined. ↓
fix Use: import depsExternal from 'rollup-plugin-deps-external'
gotcha Options like builtins, dependencies, peerDependencies default to true. If you want to exclude some, you must explicitly set them to false. ↓
fix Pass options object, e.g., depsExternal({ peerDependencies: false }).
gotcha The packagePath defaults to process.cwd(). If your package.json is elsewhere, you must provide the correct path. ↓
fix Set packagePath: path.resolve('./path/to/package.json').
Install
npm install rollup-plugin-deps-external yarn add rollup-plugin-deps-external pnpm add rollup-plugin-deps-external Imports
- depsExternal wrong
const depsExternal = require('rollup-plugin-deps-external')correctimport depsExternal from 'rollup-plugin-deps-external' - depsExternal wrong
import depsExternal from 'rollup-plugin-deps-external'correctimport { depsExternal } from 'rollup-plugin-deps-external' - depsExternal
import depsExternal from 'rollup-plugin-deps-external'
Quickstart
// rollup.config.js
import depsExternal from 'rollup-plugin-deps-external';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'es'
},
plugins: [
depsExternal()
]
};