rollup-plugin-ignore
raw JSON → 1.0.10 verified Mon Apr 27 auth: no javascript
Rollup plugin that excludes specified modules from the output bundle, replacing them with an empty default export. Current stable version is 1.0.10, with infrequent releases. It is a minimal, focused tool for preventing Node.js built-ins like `fs` or `net` from being bundled. Unlike alternatives like `@rollup/plugin-virtual`, it specifically removes the module content rather than providing stub implementations. The plugin includes a `commonjsBugFix` option to work around an issue with `@rollup/plugin-commonjs`. It ships TypeScript type definitions and is designed for use with Rollup's ESM-based plugin system.
Common errors
error Error: 'default' is not exported by node_modules/rollup-plugin-ignore/index.mjs ↓
cause Incorrect import syntax: using named import 'ignore' instead of default import.
fix
Use
import ignore from 'rollup-plugin-ignore' instead of import { ignore } from 'rollup-plugin-ignore'. error TypeError: ignore is not a function ↓
cause In CommonJS, using `require('rollup-plugin-ignore')` returns an object with `.default` property.
fix
Use
const ignore = require('rollup-plugin-ignore').default; error The plugin 'rollup-plugin-ignore' returned an empty object and will be ignored. ↓
cause The plugin is not a function; maybe imported incorrectly in Rollup config.
fix
Ensure the plugin is imported correctly as the default export and called as a function:
ignore(['fs']) in the plugins array. Warnings
gotcha The plugin replaces the entire module with an empty object; side effects such as `require('module').createServer()` will silently fail at runtime. ↓
fix Ensure you are not relying on any side effects from the ignored module.
gotcha When used with `@rollup/plugin-commonjs`, the plugin may not properly ignore CommonJS modules. Use the `commonjsBugFix` option: `ignore(modules, { commonjsBugFix: true })`. ↓
fix Add `{ commonjsBugFix: true }` as second argument to the `ignore` call.
deprecated The `commonjsBugFix` option is a workaround for an issue in `@rollup/plugin-commonjs`; it may be removed in future versions once the upstream bug is fixed. ↓
fix Keep updated with upstream changes; consider switching to a more robust solution like `@rollup/plugin-virtual` or `rollup-plugin-polyfill-node`.
Install
npm install rollup-plugin-ignore yarn add rollup-plugin-ignore pnpm add rollup-plugin-ignore Imports
- ignore (default) wrong
import { ignore } from 'rollup-plugin-ignore'correctimport ignore from 'rollup-plugin-ignore' - IgnoreOptions (type)
import type { IgnoreOptions } from 'rollup-plugin-ignore' - CommonJS require wrong
const ignore = require('rollup-plugin-ignore')correctconst ignore = require('rollup-plugin-ignore').default
Quickstart
import ignore from 'rollup-plugin-ignore';
export default {
input: 'main.js',
output: {
dir: 'output',
format: 'esm',
},
plugins: [
ignore(['fs', 'net']),
],
};