rollup-plugin-node
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript
A Rollup plugin that improves Node.js usage in Rollup bundles by automatically declaring native Node.js modules as external and removing unknown require/import statements. Version 0.2.1 is the current stable release; the plugin has no recent updates. It helps resolve issues with optional imports from external libraries that Rollup handles poorly. Differentiators: lightweight, minimal configuration, and specifically targets Node.js native modules and optional dependencies.
Common errors
error Error: Must use import to load ES Module: /path/to/rollup.config.js ↓
cause Using require() to load a config file that uses ES module syntax.
fix
Rename file to .mjs or set "type": "module" in package.json.
error TypeError: rollupPluginNode is not a function ↓
cause Default import used incorrectly (e.g., via require or destructuring).
fix
Use
import rollupPluginNode from 'rollup-plugin-node'. error [!] (rollup-plugin-node) Could not resolve 'fs' ↓
cause Plugin failed to mark Node.js native module as external.
fix
Ensure rollup-plugin-node is included in plugins array and options are correct.
Warnings
breaking Requires Rollup v1.20.0+ and Node v12.0.0+. ↓
fix Upgrade Rollup to v1.20.0+ and Node to v12.0.0+.
gotcha This plugin removes unknown require/import statements, which may silently break code with legitimate but unrecognized dynamic imports. ↓
fix Manually declare any necessary external dependencies using Rollup's external option.
gotcha Place this plugin after @rollup/plugin-commonjs for correct processing. ↓
fix Reorder plugins: commonjs, then node.
breaking The plugin uses ESM; CommonJS require is not supported. ↓
fix Use import syntax or configure your project for ESM.
Install
npm install rollup-plugin-node yarn add rollup-plugin-node pnpm add rollup-plugin-node Imports
- default wrong
const rollupPluginNode = require('rollup-plugin-node')correctimport rollupPluginNode from 'rollup-plugin-node' - rollupPluginNode wrong
import { rollupPluginNode } from 'rollup-plugin-node'correctimport rollupPluginNode from 'rollup-plugin-node' - RollupPluginNodeOptions wrong
import { RollupPluginNodeOptions } from 'rollup-plugin-node'correctimport rollupPluginNode from 'rollup-plugin-node'; type Options = Parameters<typeof rollupPluginNode>[0]
Quickstart
import rollupPluginNode from 'rollup-plugin-node';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [rollupPluginNode({
additionalOptionalDeps: {
'something.node': './addon'
}
})]
};