Node.js Core Libraries for Browsers

2.2.5 · deprecated · verified Sun Apr 19

This package, `node-libs-browser-okam` (a fork of the original `node-libs-browser`), provides browser-compatible polyfills and mock implementations for a wide range of Node.js core modules such as `buffer`, `process`, `path`, `events`, and `util`. Currently at version `2.2.5`, it is explicitly marked as deprecated and only accepts bug fixes, with no new features or breaking changes planned. Its primary use case is within module bundlers like Webpack to automatically resolve Node.js built-in module imports to browser-compatible alternatives, preventing "module not found" errors in front-end applications. The package exports a JavaScript object where keys are Node.js module names and values are the absolute paths to their respective browser implementations or `null` if no browser-compatible version is available. It relies on older versions of some key dependencies like `buffer` and `punycode` to maintain broader browser compatibility (e.g., IE9).

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the object of Node.js browser libraries and iterating through the available polyfill paths, highlighting how a bundler might resolve a module like 'buffer'.

import nodeLibs from 'node-libs-browser-okam';

console.log('Available Node.js browser libs:');

for (const libName in nodeLibs) {
  const libPath = nodeLibs[libName];
  if (libPath) {
    console.log(`- ${libName}: ${libPath}`);
  } else {
    console.log(`- ${libName}: (No browser implementation available)`);
  }
}

// Example: How a bundler might use it to resolve 'buffer'
const resolvedBufferPath = nodeLibs.buffer;
if (resolvedBufferPath) {
  console.log(`\nPath to buffer polyfill: ${resolvedBufferPath}`);
} else {
  console.log('\nBuffer polyfill not found.');
}

// This package is primarily used by bundlers like Webpack for automatic aliasing.
// For direct usage, you would typically configure a bundler to use these paths.

view raw JSON →