node-stdlib-browser provides polyfills for Node.js standard library modules, enabling code that relies on these Node.js built-ins to run in browser environments. It serves as a actively maintained alternative to the original `node-libs-browser` package, which is deprecated. Version 1.3.1 is the current stable release. The package does not adhere to a strict time-based release cadence but sees regular updates for dependency bumps, bug fixes, and new bundler support. Key differentiators include explicit support for modern bundlers like Webpack, Rollup, Vite, and esbuild, as well as handling the `node:` protocol for built-in module imports.
npm install node-stdlib-browserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure Vite to use `node-stdlib-browser` for polyfilling Node.js built-in modules in a browser environment. It sets up aliases and injects global variables like `process` and `Buffer` using `@rollup/plugin-inject`.
Refer to the package's documentation for Webpack configuration, ensuring `resolve.alias` and `webpack.ProvidePlugin` are correctly set up, along with `NodeProtocolUrlPlugin` for `node:` protocol imports.
Add a rule to your `webpack.config.js` to disable `fullySpecified` for JavaScript modules: `module: { rules: [{ test: /\.m?js$/, resolve: { fullySpecified: false } }] }`.Utilize the `handleCircularDependancyWarning` helper function from `node-stdlib-browser/helpers/rollup/plugin` in your Rollup `onwarn` hook to filter or ignore these specific warnings.
Ensure your Vite configuration uses `await import('node-stdlib-browser')` and sets `enforce: 'post'` on the `@rollup/plugin-inject` configuration.For Webpack, ensure `webpack.ProvidePlugin` is configured to map `process` and `Buffer`. For Rollup/Vite/esbuild, ensure an `inject` plugin (e.g., `@rollup/plugin-inject`) is set up to provide these globals, typically pointing to `node-stdlib-browser`'s implementations.
Verify that your bundler's configuration (e.g., `webpack.config.js`, `rollup.config.js`, `vite.config.js`) includes `node-stdlib-browser` in its `resolve.alias` section.
This often points to a larger issue with `node:` protocol imports or mixed ESM/CJS modules. Consider using `vite-plugin-node-polyfills` or carefully reviewing the `node-stdlib-browser` documentation for Vite regarding dynamic imports and plugin enforcement. You might also need to explicitly mark certain modules as external in your bundler configuration if they are causing issues.
Ensure that the esbuild `inject` configuration correctly references the shim, and that no other configurations are inadvertently marking it as external. This might involve specific plugin order or configuration details depending on your bundler version.
No dependency data recorded yet.