Registry / http-networking / rollup-plugin-node-polyfills

rollup-plugin-node-polyfills

JSON →
library0.2.1jsnpmunverified

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.

npm install rollup-plugin-node-polyfills
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-NODE
R
rollup-plugin-node-polyfills
http-networkingjavascriptv0.2.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

nodePolyfills
✓ import nodePolyfills from 'rollup-plugin-node-polyfills';
✗ const nodePolyfills = require('rollup-plugin-node-polyfills');
Rollup configuration files are typically written in ESM, so `import` syntax is preferred. CommonJS `require` is generally not used for plugin imports in modern Rollup setups.
EventEmitter
✓ import EventEmitter from 'events';
✗ const EventEmitter = require('events');
The plugin provides ES6 specific versions for many modules, allowing named imports or default imports for common patterns like `EventEmitter` from `events`. While `require` might technically work in the bundled output for some cases, using `import` is idiomatic for ES modules.
inherits
✓ import { inherits } from 'util';
✗ import util from 'util'; const inherits = util.inherits;
For modules that tree-shake well (like `util`), named imports for specific functions like `inherits` are efficient and supported by the plugin.
Buffer
✓ import { Buffer } from 'buffer';
✗ const Buffer = require('buffer').Buffer;
When using the `buffer` polyfill, `Buffer` is typically imported as a named export. The plugin aims to provide ES6-compatible access.

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() ] };
Debug
Known issues
breakingThis package, `rollup-plugin-node-polyfills` (from Ionic Team), is abandoned and has not been updated since version `0.2.1` (last published June 2019). It is not actively maintained and may have unaddressed bugs or security vulnerabilities.
fix
Migrate to `rollup-plugin-polyfill-node` (a community-maintained fork) for active development and better Node.js polyfills, or `@frida/rollup-plugin-node-polyfills` if your project specifically uses Frida's shims.
affects: >=0.2.1
gotchaThe `crypto` module is not effectively shimmed by default and provides limited functionality, primarily from a browserify CommonJS shim.
fix
Pass `{crypto: true}` as an option to the plugin to enable the browserified shim, but be aware that full `crypto` functionality is unlikely to be available in a browser environment.
affects: >=0.2.1
gotchaModules such as `http`, `https`, and `stream` contain circular references, which can significantly hinder tree-shaking and lead to larger bundle sizes.
fix
Carefully evaluate dependencies on these modules. If possible, refactor code to avoid them or explore alternative browser-native solutions. Be aware of the potential for larger bundles if these modules are included.
affects: >=0.2.1
gotchaSeveral Node.js modules (e.g., `dns`, `dgram`, `child_process`, `cluster`, `module`, `net`, `readline`, `repl`, `tls`) are not truly shimmed; they only return mock objects, rendering their functionality essentially unavailable in the browser environment.
fix
Avoid relying on these modules entirely when targeting browser environments with this plugin. These APIs are inherently Node.js-specific and generally cannot be meaningfully polyfilled in a browser.
affects: >=0.2.1
gotchaThe `fs` (file system) module's browserified shim is optional and not included by default.
fix
Enable the `fs` shim explicitly by passing `{fs: true}` as an option to the plugin if you require its limited browser-compatible functionality.
affects: >=0.2.1
gotchaThe `vm` module has known limitations and does not support all corner cases, especially when used in web workers.
fix
Test `vm` module usage thoroughly in your target environments and consider its inherent limitations for complex or security-sensitive scenarios.
affects: >=0.2.1
Errors
Common errors & fixes
Module not found: Can't resolve 'events'
A Node.js built-in module is being imported or required in a Rollup bundle without `rollup-plugin-node-polyfills` being configured or the specific polyfill failing.
fix
Ensure `rollup-plugin-node-polyfills` is correctly installed and added to your Rollup plugins array. If using a specific module like `crypto` or `fs`, ensure it's explicitly enabled via plugin options. Consider migrating to `rollup-plugin-polyfill-node`.
TypeError: process.nextTick is not a function
Code relies on a `process` API (`process.nextTick`) that is either not fully polyfilled or the `process` polyfill isn't correctly applied.
fix
Verify the plugin is active and correctly processes files where `process` is used. For modern projects, it's recommended to use `rollup-plugin-polyfill-node` for better `process` polyfill support.
Uncaught ReferenceError: Buffer is not defined
The `Buffer` global or import is not being correctly provided by the polyfill, or code is attempting to use `Buffer` without importing it explicitly.
fix
Ensure `import { Buffer } from 'buffer';` is present where `Buffer` is used. Verify the `buffer` polyfill is active through the plugin. Consider using a newer polyfill plugin if issues persist.
TypeError: require is not a function
Your bundled code (intended for the browser) contains `require()` calls for Node.js modules, and the plugin failed to transform them into browser-compatible imports.
fix
Confirm the plugin is enabled and configured to process all relevant files (`include` option). For better reliability, especially in modern Rollup setups, use `import` statements over `require()` where possible and upgrade to `rollup-plugin-polyfill-node`.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
rolluprequiredThis is a Rollup plugin and requires Rollup as a peer dependency for its functionality.
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
1
Resources
rollup-plugin-node-polyfills — npm install rollup-plugin-node-polyfills · libregistry