{"id":15807,"library":"rollup-plugin-node-polyfills","title":"Rollup Plugin for Node.js Polyfills (Legacy)","description":"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.","status":"abandoned","version":"0.2.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/ionic-team/rollup-plugin-node-polyfills","tags":["javascript","rollup-plugin","typescript"],"install":[{"cmd":"npm install rollup-plugin-node-polyfills","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-node-polyfills","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-node-polyfills","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Rollup plugin and requires Rollup as a peer dependency for its functionality.","package":"rollup","optional":false}],"imports":[{"note":"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.","wrong":"const nodePolyfills = require('rollup-plugin-node-polyfills');","symbol":"nodePolyfills","correct":"import nodePolyfills from 'rollup-plugin-node-polyfills';"},{"note":"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.","wrong":"const EventEmitter = require('events');","symbol":"EventEmitter","correct":"import EventEmitter from 'events';"},{"note":"For modules that tree-shake well (like `util`), named imports for specific functions like `inherits` are efficient and supported by the plugin.","wrong":"import util from 'util'; const inherits = util.inherits;","symbol":"inherits","correct":"import { inherits } from 'util';"},{"note":"When using the `buffer` polyfill, `Buffer` is typically imported as a named export. The plugin aims to provide ES6-compatible access.","wrong":"const Buffer = require('buffer').Buffer;","symbol":"Buffer","correct":"import { Buffer } from 'buffer';"}],"quickstart":{"code":"import nodePolyfills from 'rollup-plugin-node-polyfills';\nimport EventEmitter from 'events';\nimport { inherits } from 'util';\nimport { Buffer } from 'buffer';\n\nconst eventEmitter = new EventEmitter();\nconsole.log(eventEmitter instanceof EventEmitter);\n\nclass MyClass {}\ninherits(MyClass, EventEmitter);\nconst myInstance = new MyClass();\nconsole.log(myInstance instanceof EventEmitter);\n\nconst buf = Buffer.from('hello');\nconsole.log(buf.toString());\n\nexport default {\n  input: 'main.js',\n  output: {\n    file: 'bundle.js',\n    format: 'esm'\n  },\n  plugins: [\n    nodePolyfills()\n  ]\n};","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=0.2.1"},{"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.","message":"The `crypto` module is not effectively shimmed by default and provides limited functionality, primarily from a browserify CommonJS shim.","severity":"gotcha","affected_versions":">=0.2.1"},{"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.","message":"Modules such as `http`, `https`, and `stream` contain circular references, which can significantly hinder tree-shaking and lead to larger bundle sizes.","severity":"gotcha","affected_versions":">=0.2.1"},{"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.","message":"Several 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.","severity":"gotcha","affected_versions":">=0.2.1"},{"fix":"Enable the `fs` shim explicitly by passing `{fs: true}` as an option to the plugin if you require its limited browser-compatible functionality.","message":"The `fs` (file system) module's browserified shim is optional and not included by default.","severity":"gotcha","affected_versions":">=0.2.1"},{"fix":"Test `vm` module usage thoroughly in your target environments and consider its inherent limitations for complex or security-sensitive scenarios.","message":"The `vm` module has known limitations and does not support all corner cases, especially when used in web workers.","severity":"gotcha","affected_versions":">=0.2.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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`.","cause":"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.","error":"Module not found: Can't resolve 'events'"},{"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.","cause":"Code relies on a `process` API (`process.nextTick`) that is either not fully polyfilled or the `process` polyfill isn't correctly applied.","error":"TypeError: process.nextTick is not a function"},{"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.","cause":"The `Buffer` global or import is not being correctly provided by the polyfill, or code is attempting to use `Buffer` without importing it explicitly.","error":"Uncaught ReferenceError: Buffer is not defined"},{"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`.","cause":"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.","error":"TypeError: require is not a function"}],"ecosystem":"npm"}