{"id":15239,"library":"stream-browserify","title":"Node.js Stream API for Browsers (Browserify)","description":"stream-browserify is a module that provides the Node.js `stream` API for browser environments. It serves as a polyfill, allowing npm packages designed for Node.js streams to function correctly within a browser context when bundled. The current stable version is 3.0.0, released after a period of using `readable-stream` v2, and now fully leverages `readable-stream` v3. This package is primarily intended for use with bundlers like Browserify, which automatically substitute the native Node.js `stream` module with `stream-browserify` during the bundling process. Its key differentiator is providing a consistent, spec-compliant stream implementation that bridges the gap between Node.js module expectations and browser limitations, ensuring broad compatibility for legacy and modern stream APIs in the browser.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/browserify/stream-browserify","tags":["javascript","stream","browser","browserify"],"install":[{"cmd":"npm install stream-browserify","lang":"bash","label":"npm"},{"cmd":"yarn add stream-browserify","lang":"bash","label":"yarn"},{"cmd":"pnpm add stream-browserify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying stream implementation, upgraded to v3 in stream-browserify v3.0.0.","package":"readable-stream","optional":false}],"imports":[{"note":"While named imports are supported for direct usage, bundlers like Browserify typically remap `require('stream')` to this module.","wrong":"const Readable = require('stream-browserify').Readable;","symbol":"Readable","correct":"import { Readable } from 'stream-browserify';"},{"note":"All stream classes are exported as named exports from the main entry point.","wrong":"import Writable from 'stream-browserify/writable';","symbol":"Writable","correct":"import { Writable } from 'stream-browserify';"},{"note":"CommonJS `require('stream-browserify').Transform` is also a valid pattern, especially when using Browserify which shims `require('stream')`.","wrong":"const stream = require('stream-browserify'); const Transform = stream.Transform;","symbol":"Transform","correct":"import { Transform } from 'stream-browserify';"}],"quickstart":{"code":"import { Readable, Writable } from 'stream-browserify';\n\nclass MyReadable extends Readable {\n  constructor(options) {\n    super(options);\n    this.index = 0;\n  }\n\n  _read(size) {\n    if (this.index < 5) {\n      this.push(`Chunk ${this.index++}\\n`);\n    } else {\n      this.push(null); // No more data\n    }\n  }\n}\n\nclass MyWritable extends Writable {\n  _write(chunk, encoding, callback) {\n    console.log(`Received: ${chunk.toString()}`);\n    callback();\n  }\n}\n\nconst readableStream = new MyReadable();\nconst writableStream = new MyWritable();\n\nreadableStream.pipe(writableStream);\n\n// Expected output:\n// Received: Chunk 0\n// Received: Chunk 1\n// Received: Chunk 2\n// Received: Chunk 3\n// Received: Chunk 4\n","lang":"javascript","description":"Demonstrates creating and piping a basic readable stream to a writable stream using `stream-browserify`."},"warnings":[{"fix":"Review the `readable-stream` v3 documentation for breaking changes (e.g., changes to `_read` behavior, error handling, `pipeline`, and `finished` utilities). Adapt stream implementations and consumption patterns accordingly.","message":"Version 3.0.0 upgrades to `readable-stream` v3. This introduces several breaking changes inherited from `readable-stream` itself, aligning with Node.js 10+ stream APIs. Developers should consult the `readable-stream` v3 release notes for detailed information.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If using Browserify, avoid explicit `npm install stream-browserify` unless a specific version conflict or direct module access is required. Rely on the bundler's resolution.","message":"Direct installation of `stream-browserify` is often unnecessary. Bundlers like Browserify automatically include and alias this module when `require('stream')` is encountered in browser environments.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `npm ls readable-stream` or `yarn why readable-stream` to inspect your dependency tree. Resolve any duplicate or conflicting `readable-stream` versions to ensure a consistent stream implementation across your project. Consider `resolutions` or `overrides` if necessary.","message":"Mixing different versions of `readable-stream` (or `stream-browserify` which depends on it) within a single application can lead to unpredictable behavior and compatibility issues, especially when libraries expect specific stream API behaviors.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure your project is bundled with a tool like Browserify that provides `stream-browserify` as a shim for `require('stream')`. If directly importing, use `import { Readable } from 'stream-browserify';`. Verify bundler configuration.","cause":"This typically occurs in a browser environment where the native Node.js 'stream' module is not available or has not been correctly polyfilled by a bundler, or if an old CJS `require` is used in an incompatible ESM context.","error":"TypeError: stream.Readable is not a constructor"},{"fix":"If using Browserify, ensure `stream-browserify` is correctly integrated by the bundler. If not using a bundler or needing a global stream polyfill, you might need to manually configure aliasing or ensure `stream-browserify` is included in your build process.","cause":"This error means that `require('stream')` or `import 'stream'` could not be resolved, most commonly in a browser environment without an appropriate polyfill or bundler configuration.","error":"Cannot find module 'stream'"}],"ecosystem":"npm"}