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-polyfillsVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.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.
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.
Enable the `fs` shim explicitly by passing `{fs: true}` as an option to the plugin if you require its limited browser-compatible functionality.Test `vm` module usage thoroughly in your target environments and consider its inherent limitations for complex or security-sensitive scenarios.
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`.
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.
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.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`.