Rollup Plugin for Node.js Built-ins

2.1.2 · abandoned · verified Sun Apr 19

This Rollup plugin shims Node.js built-in modules, enabling projects designed for a Node.js environment or Browserify to run in a browser bundle. It allows `require` or `import` statements for modules like `events`, `util`, `path`, and `buffer` to be resolved during the Rollup bundling process. The latest stable version is 2.1.2, released in 2017. Due to its age, it is no longer actively maintained and may have compatibility issues with newer Rollup versions or modern JavaScript features. For many built-ins (marked with an asterisk in the README), it requires the companion `rollup-plugin-node-globals` for proper functionality, especially for `process` and `Buffer`. Key differentiators at the time of its release were its ability to provide Browserify-compatible shims within the Rollup ecosystem, bridging a gap for projects with existing Node.js module dependencies. However, more modern alternatives like `@rollup/plugin-node-resolve` (with specific configuration) or `rollup-plugin-polyfill-node` are now generally recommended.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates bundling an application that uses Node.js `http` or `events` modules for a browser environment, correctly ordering `globals` and `builtins` plugins.

import rollup from 'rollup';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';

async function build() {
  const bundle = await rollup.rollup({
    input: 'main.js',
    plugins: [
      globals(), // Must come before builtins for proper context setup
      builtins() // Enables Node.js built-ins
    ]
  });

  await bundle.write({
    file: 'bundle.js',
    format: 'iife',
    name: 'MyBundle',
    sourcemap: true
  });
  console.log('Rollup build complete!');
}

// Example main.js content for context (not part of quickstart code itself)
// import * as http from 'http';
// http.request('http://example.com');
// import { EventEmitter } from 'events';
// const emitter = new EventEmitter();

build().catch(console.error);

view raw JSON →