Registry / devops / rollup-plugin-node-builtins

rollup-plugin-node-builtins

JSON →
library2.1.2jsnpmunverified

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.

npm install rollup-plugin-node-builtins
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-NODE
R
rollup-plugin-node-builtins
devopsjavascriptv2.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

builtins
import builtins from 'rollup-plugin-node-builtins';
const builtins = require('rollup-plugin-node-builtins');
While Rollup configs can be CJS, the modern practice is ESM. The plugin itself is typically imported as a default export.
EventEmitter
import EventEmitter from 'events';
const EventEmitter = require('events');
For shimmed Node.js built-ins like 'events', the plugin enables them to be imported directly as if they were browser-compatible ESM modules.
inherits
import { inherits } from 'util';
import util from 'util'; const { inherits } = util;
Many built-ins offer named exports (indicated by ES6 specific versions). Always prefer named imports for better tree-shaking, where available.

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);
Debug
Known issues
breakingThis package is unmaintained. The last update was in 2017 (v2.1.2). It may not be compatible with newer Rollup versions (e.g., Rollup 3+) or modern JavaScript syntax/features like dynamic imports, potentially causing build failures or runtime errors.
fix
Consider migrating to actively maintained alternatives like `rollup-plugin-polyfill-node` or configuring `@rollup/plugin-node-resolve` with `preferBuiltins: false` and explicitly providing browser shims, or using a more modern bundler.
affects: >=2.1.2
gotchaMany Node.js built-in modules (e.g., `process`, `stream`, `http`, `buffer`) require `rollup-plugin-node-globals` to be used *before* `rollup-plugin-node-builtins` in the Rollup plugin array. Failing to include or correctly order `node-globals` will result in unresolved references (`process is not defined`) for modules depending on global Node variables.
fix
Ensure `rollup-plugin-node-globals` is installed and placed before `rollup-plugin-node-builtins` in your `rollup.config.js` plugins array.
affects: >=1.0.0
gotchaSome Node.js built-in modules are not fully shimmed or have limitations. For example, `vm` has fewer corner cases handled, `http` and `https` are the same (no protocol differentiation), and modules like `dns`, `dgram`, `child_process`, `cluster`, `module`, `net`, `readline`, `repl`, and `tls` only return mocks, making them largely unusable.
fix
Review the plugin's README to understand the limitations of each shim. Avoid using severely limited or mock-only modules where true Node.js functionality is expected in a browser.
affects: >=1.0.0
gotchaThe `crypto` and `fs` modules are *optional* and require explicit configuration (`{crypto: true}` or `{fs: true}`) to be enabled. Without this, attempts to `import` or `require` them will likely fail or use a basic, potentially non-functional CommonJS shim from Browserify.
fix
Pass `{ crypto: true }` or `{ fs: true }` as options to the `builtins()` plugin call if you intend to use these modules: `builtins({ crypto: true })`.
affects: >=1.0.0
gotchaSome shimmed modules, particularly `streams` and anything that depends on them (like `http`), have complex circular references which significantly hinder Rollup's tree-shaking capabilities, leading to larger-than-expected bundle sizes. `url` methods also don't tree-shake well.
fix
For optimal bundle size, avoid importing heavy or circular-reference-prone Node.js built-ins. If essential, perform aggressive dead code elimination (e.g., via `terser`) as a post-processing step, but be aware of its limitations for these specific modules.
affects: >=1.0.0
Errors
Common errors & fixes
(!) Missing Node.js built-in module 'punycode' (or similar built-in) ... You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins
A dependency in your project or your own code is trying to import a Node.js built-in module, but `rollup-plugin-node-builtins` is either not installed, not configured, or configured incorrectly (e.g., wrong order relative to `node-globals`).
fix
Ensure `rollup-plugin-node-builtins` is installed and added to your `rollup.config.js` plugins array. If the module is one that requires `rollup-plugin-node-globals`, ensure `globals()` is before `builtins()`.
ReferenceError: process is not defined
A module in your bundle expects the global `process` object (a Node.js global), but `rollup-plugin-node-globals` (which provides shims for globals like `process` and `Buffer`) is not included or is incorrectly ordered.
fix
Install `rollup-plugin-node-globals` and add `globals()` to your Rollup plugins array, ensuring it appears *before* `builtins()`.
TypeError: Cannot read properties of undefined (reading 'randomBytes')
Attempted to use the `crypto` module without explicitly enabling it in `rollup-plugin-node-builtins` options.
fix
Enable the `crypto` shim by configuring the plugin as `builtins({ crypto: true })`.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
rollup-plugin-node-globalsrequiredRequired for many built-in modules like 'process', 'stream', 'util', 'buffer', 'http', 'https', 'os', 'assert', 'timers', 'console', 'vm', 'zlib', and 'fs' to be properly shimmed in the browser environment.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
rollup-plugin-node-builtins — npm install rollup-plugin-node-builtins · libregistry