Registry / http-networking / node-libs-browser

node-libs-browser

JSON →
library2.2.1jsnpmunverified

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.

npm install node-libs-browser
INSTALL
IMPORT
SIG · NODE-LIBS-BROWSER
N
node-libs-browser
http-networkingjavascriptv2.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

nodeLibs
const nodeLibs = require('node-libs-browser');
import nodeLibs from 'node-libs-browser';
Primarily used in CommonJS contexts (e.g., bundler configurations). While ESM imports may work in some setups, `require` is more historically accurate for this package's typical usage.
bufferPath
const bufferPath = require('node-libs-browser').buffer;
import { buffer } from 'node-libs-browser';
The package exports an object where keys are module names and values are *paths* to their browser implementations or `null`, not named exports of the modules themselves. Attempting to destructure directly will fail.
fsModule
const fsModule = require('node-libs-browser').fs;
require('node-libs-browser/fs');
Access individual module paths as properties of the imported object. Direct subpath imports (e.g., `require('node-libs-browser/fs')`) are not the intended API and will likely result in a module not found error.

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.
Debug
Known issues
deprecatedThis library is officially deprecated and is in maintenance mode. It will not receive new features or breaking changes, only critical bug fixes. Users should consider modern alternatives like `node-stdlib-browser` for active development and better compatibility with newer Node.js versions and ESM.
fix
Migrate to actively maintained alternatives or ensure your bundler configuration handles Node.js polyfills explicitly without relying solely on this package.
affects: >=2.2.1
gotchaThe `buffer` implementation (`feross/buffer@4.x`) is outdated and does not support features reliant on Typed Arrays found in `feross/buffer@5.x`. This decision was made to maintain compatibility with older browsers like IE9.
fix
If modern `Buffer` API features are required and IE9 compatibility is not a concern, you may need to explicitly configure your bundler to use a newer `buffer` polyfill or an alternative package.
affects: >=2.2.0
gotchaThe `punycode` implementation (`bestiejs/punycode.js@1.x`) is outdated and does not support modern JavaScript engines (requiring `const` and `let` for newer versions). The Node.js `punycode` module itself is also deprecated since Node.js v21/22.
fix
For projects running on newer Node.js versions, address `punycode` deprecation warnings by updating dependencies that might be transitively relying on it, or using an explicit userland `punycode.js` package and configuring bundler aliases.
affects: >=2.2.0
gotchaMany Node.js core modules (e.g., `child_process`, `cluster`, `fs`, `net`, `tls`) are explicitly `null` in `node-libs-browser`, meaning no browser implementation or mock is provided. Code attempting to use these will fail in the browser.
fix
Refactor application code to avoid Node.js-specific modules in browser contexts, use conditional imports for environment-specific code, or explicitly mock/polyfill unavailable modules if essential.
affects: *
gotchaThis package is primarily a low-level utility for bundlers like Webpack. Direct integration into application logic for polyfilling purposes is generally discouraged. Improper configuration or direct usage can lead to unexpected behavior or larger bundle sizes.
fix
Ensure `node-libs-browser` is configured via your bundler's options (e.g., Webpack's `resolve.alias` or `node` options) rather than being manually imported and consumed in application code. Consider bundler-specific plugins or alternatives that provide more opinionated or modern approaches to polyfilling.
affects: *
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'fs' in 'your-module-path'
An application or one of its dependencies is attempting to `require('fs')` (or another Node.js-specific module) in a browser environment, and `node-libs-browser` does not provide a browser implementation or mock for it (its value is `null`).
fix
Review the usage of Node.js core modules. For modules with `null` implementations, refactor the code to avoid them in browser contexts, or use a specific, actively maintained browser polyfill if available and appropriate, configuring your bundler to alias it.
Uncaught ReferenceError: process is not defined
Code running in the browser expects the global `process` object (a Node.js global), but the `process` polyfill provided by `node-libs-browser` or a similar solution has not been correctly applied by the bundler.
fix
Ensure your bundler's configuration (e.g., Webpack's `NodeSourcePlugin`, `node` option, or `ProvidePlugin`) correctly sets up the `process` polyfill. Verify that `node-libs-browser` (or its `process` sub-dependency) is included and active.
Buffer.from is not a function
The `buffer` polyfill being used (often `feross/buffer@4.x` from `node-libs-browser`) is an older version that predates the `Buffer.from` and `Buffer.alloc` APIs introduced in Node.js v6.
fix
If your application requires modern `Buffer` APIs, you must explicitly configure your bundler to use a newer `buffer` polyfill (e.g., `feross/buffer@5.x` or later) and accept potential compatibility issues with very old browsers like IE9.
(node:XXXX) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
Your Node.js environment is v21 or newer, and `node-libs-browser` (or a dependency transitively) is using the deprecated bundled `punycode` module.
fix
Run `npm ls punycode` to identify the direct or transitive dependency. If `node-libs-browser` is the culprit, consider migrating to a more modern alternative like `node-stdlib-browser` which addresses this, or use bundler `overrides` to force a newer, userland `punycode.js` version.
Upgrade
Version history
2.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources