Node.js Core Libraries for Browser Environments

2.2.1 · deprecated · verified Sun Apr 19

node-libs-browser is a utility package providing browser-compatible polyfills and mock implementations for a subset of Node.js core modules. Its primary purpose is to enable bundlers like Webpack to resolve `require('fs')` or `require('buffer')` in browser environments, substituting Node.js-specific APIs with browser-friendly alternatives. The current stable version is 2.2.1. This library is officially deprecated, meaning it will not accept new features or breaking changes; only bugfixes. Its release cadence is effectively stalled, with the last major update several years ago. While historically critical for enabling Node.js code in the browser, modern development often favors more granular polyfills, conditional imports, or alternatives like `node-stdlib-browser` that are actively maintained and offer newer implementations and ESM support, addressing issues like `punycode` deprecation in newer Node.js versions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import `node-libs-browser` and iterate through the provided Node.js core library mappings, showing which modules have browser implementations or mocks.

import nodeLibs from 'node-libs-browser';

console.log('Available Node.js core library browser implementations:');

for (const libName in nodeLibs) {
  const implementationPath = nodeLibs[libName];
  if (implementationPath) {
    console.log(`- ${libName}: ${implementationPath} (Browser implementation/mock available)`);
  } else {
    console.log(`- ${libName}: (No browser implementation or mock provided by node-libs-browser)`);
  }
}

// This library is primarily used internally by bundlers like Webpack.
// For example, Webpack's NodeSourcePlugin uses this mapping to resolve
// Node.js core module imports to browser-compatible versions or mocks.
// You typically don't directly import and use the paths in your application code.
// For instance, if your application code has 'require("path")',
// Webpack (using node-libs-browser) would internally map it to the path-browserify implementation.

view raw JSON →