Node Standard Library for Browser

1.3.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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`.

import { defineConfig } from 'vite';
import inject from '@rollup/plugin-inject';

const esbuildShim = require.resolve('node-stdlib-browser/helpers/esbuild/shim');

export default async () => {
  const { default: stdLibBrowser } = await import('node-stdlib-browser');
  return {
    resolve: {
      alias: stdLibBrowser,
    },
    optimizeDeps: {
      include: ['buffer', 'process'],
    },
    plugins: [
      {
        ...inject({
          global: [esbuildShim, 'global'],
          process: [esbuildShim, 'process'],
          Buffer: [esbuildShim, 'Buffer'],
        }),
        enforce: 'post',
      },
    ],
  };
};

view raw JSON →