{"id":11433,"library":"node-libs-browser-okam","title":"Node.js Core Libraries for Browsers","description":"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).\n","status":"deprecated","version":"2.2.5","language":"javascript","source_language":"en","source_url":"https://github.com/webpack/node-libs-browser","tags":["javascript"],"install":[{"cmd":"npm install node-libs-browser-okam","lang":"bash","label":"npm"},{"cmd":"yarn add node-libs-browser-okam","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-libs-browser-okam","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a default object containing paths to browser polyfills. Named imports are incorrect.","wrong":"import { nodeLibs } from 'node-libs-browser-okam';","symbol":"nodeLibs","correct":"import nodeLibs from 'node-libs-browser-okam';"},{"note":"CommonJS `require` is the most common way to import this package due to its age and common usage in bundler configurations.","symbol":"nodeLibs","correct":"const nodeLibs = require('node-libs-browser-okam');"},{"note":"Individual module paths are accessed as properties on the default exported object.","wrong":"import { buffer } from 'node-libs-browser-okam';","symbol":"bufferPath","correct":"const bufferPath = require('node-libs-browser-okam').buffer;"}],"quickstart":{"code":"import nodeLibs from 'node-libs-browser-okam';\n\nconsole.log('Available Node.js browser libs:');\n\nfor (const libName in nodeLibs) {\n  const libPath = nodeLibs[libName];\n  if (libPath) {\n    console.log(`- ${libName}: ${libPath}`);\n  } else {\n    console.log(`- ${libName}: (No browser implementation available)`);\n  }\n}\n\n// Example: How a bundler might use it to resolve 'buffer'\nconst resolvedBufferPath = nodeLibs.buffer;\nif (resolvedBufferPath) {\n  console.log(`\\nPath to buffer polyfill: ${resolvedBufferPath}`);\n} else {\n  console.log('\\nBuffer polyfill not found.');\n}\n\n// This package is primarily used by bundlers like Webpack for automatic aliasing.\n// For direct usage, you would typically configure a bundler to use these paths.","lang":"javascript","description":"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'."},"warnings":[{"fix":"Review your project's dependency on `node-libs-browser-okam` and explore more actively maintained polyfills or ensure your bundler (e.g., Webpack 5+) has native fallbacks or custom resolutions configured.","message":"The `node-libs-browser` project is officially deprecated and only accepts bug fixes. No new features or breaking changes will be introduced. Users should consider modern alternatives for polyfilling Node.js built-ins in browser environments, or ensure their bundler explicitly handles these.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"If your code requires `Buffer.from()` or other modern `Buffer` APIs, you may need to explicitly import a newer `buffer` polyfill or use an alternative method like `new Buffer()` (which is deprecated in Node.js itself but works with this polyfill).","message":"The `buffer` implementation uses `feross/buffer@4.x` instead of the newer `5.x` version. This is due to a deliberate choice to support older browsers (like IE9) by avoiding reliance on typed arrays. Consequently, `Buffer.from()` and other modern `Buffer` static methods are not available.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"If specific modern `punycode` functionalities are required, consider importing a more up-to-date `punycode` polyfill directly rather than relying on the one provided by `node-libs-browser-okam`.","message":"The `punycode` implementation uses `bestiejs/punycode.js@1.x`, which requires older JavaScript engines. This means it may not be compatible with newer `punycode` APIs or expectations of modern JavaScript syntax.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Avoid importing these Node.js-specific modules in browser code. If their functionality is critical, you must find entirely different browser-native solutions or refactor your application logic.","message":"Many Node.js core modules, such as `child_process`, `cluster`, `dgram`, `fs`, `module`, `net`, `readline`, `repl`, `tls`, do not have browser-compatible implementations within this package. Their entries in the exported object are `null`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Remove the problematic import from your browser-side code. These modules are fundamentally tied to the Node.js environment and typically cannot be replicated in a browser. Re-evaluate your architecture if such functionality is critical for the client.","cause":"Attempting to import a Node.js core module (like `fs`, `net`, `child_process`) that `node-libs-browser-okam` does not provide a browser polyfill for (its entry in the exported object is `null`).","error":"Module not found: Error: Can't resolve 'fs' in '/path/to/your/project'"},{"fix":"Refactor your code to use `new Buffer(array)` or `new Buffer(string, encoding)` instead of `Buffer.from()`. Alternatively, you can configure your bundler to alias `buffer` to a different, more modern polyfill that supports `Buffer.from()`.","cause":"Code expects the `Buffer.from()` static method, but `node-libs-browser-okam` uses an older `feross/buffer@4.x` polyfill which predates this API, primarily supporting `new Buffer()`.","error":"TypeError: Buffer.from is not a function"},{"fix":"Ensure your bundler (e.g., Webpack, Rollup, Browserify) has `node-libs-browser-okam` or a similar polyfill configured to correctly alias the global `process` object. For Webpack, this often involves configuring `resolve.fallback` or `ProvidePlugin` for older versions.","cause":"The global `process` object, expected by some Node.js modules, is not correctly aliased to its browser polyfill by the bundler, or accessed in a context where the polyfill isn't available.","error":"ReferenceError: process is not defined"},{"fix":"Review the specific `crypto` function being called. If it's not implemented, you'll need to find a dedicated browser-compatible cryptography library that provides the required functionality, or refactor your code to avoid the unsupported API.","cause":"While `crypto` has a browser polyfill, it may not implement all functions available in Node.js's native `crypto` module, leading to runtime errors for unsupported APIs.","error":"Uncaught TypeError: crypto.createHash is not a function"}],"ecosystem":"npm"}