Rollup Plugin for Node.js Polyfills (Legacy)

0.2.1 · abandoned · verified Tue Apr 21

The `rollup-plugin-node-polyfills` package, currently at version `0.2.1` and last published over 7 years ago, is an abandoned Rollup plugin designed to provide browser-compatible polyfills or shims for Node.js built-in modules. Its primary function was to allow Rollup to bundle code containing `require()` or `import` statements for Node.js core modules (such as `events`, `path`, `buffer`, `http`, and `util`) when targeting a browser environment. The plugin leverages ES6 ports of Browserify modules for its polyfills, enabling both named and default imports for many modules. However, due to its inactive maintenance, developers are strongly advised to use modern, actively maintained alternatives like `rollup-plugin-polyfill-node` to ensure compatibility, security, and access to up-to-date polyfills. This legacy plugin has known limitations, including incomplete shims for certain modules, issues with tree-shaking for complex modules like `stream` and `http` due to circular references, and modules that only return mock objects instead of functional polyfills.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic Rollup configuration using the `nodePolyfills` plugin and shows how to import and use a few polyfilled Node.js built-in modules like `events`, `util`, and `buffer` in the `main.js` entry point.

import nodePolyfills from 'rollup-plugin-node-polyfills';
import EventEmitter from 'events';
import { inherits } from 'util';
import { Buffer } from 'buffer';

const eventEmitter = new EventEmitter();
console.log(eventEmitter instanceof EventEmitter);

class MyClass {}
inherits(MyClass, EventEmitter);
const myInstance = new MyClass();
console.log(myInstance instanceof EventEmitter);

const buf = Buffer.from('hello');
console.log(buf.toString());

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'esm'
  },
  plugins: [
    nodePolyfills()
  ]
};

view raw JSON →