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-builtinsVerified import paths — ran on the pinned version, not inferred.
Demonstrates bundling an application that uses Node.js `http` or `events` modules for a browser environment, correctly ordering `globals` and `builtins` plugins.
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.
Ensure `rollup-plugin-node-globals` is installed and placed before `rollup-plugin-node-builtins` in your `rollup.config.js` plugins array.
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.
Pass `{ crypto: true }` or `{ fs: true }` as options to the `builtins()` plugin call if you intend to use these modules: `builtins({ crypto: true })`.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.
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()`.
Install `rollup-plugin-node-globals` and add `globals()` to your Rollup plugins array, ensuring it appears *before* `builtins()`.
Enable the `crypto` shim by configuring the plugin as `builtins({ crypto: true })`.