{"id":15224,"library":"readable-stream-node-to-web","title":"Node.js Readable Stream to Web ReadableStream Converter","description":"The `readable-stream-node-to-web` package offers a utility to convert a Node.js `Readable` stream into a WHATWG `ReadableStream`, commonly known as a web stream. This bridge allows developers to use Node.js stream-producing modules within web-native contexts such as Service Workers or modern browser environments, where web streams are the standard. The current and last published stable version is 1.0.1, released approximately nine years ago. Due to its age and the subsequent introduction of native stream conversion utilities directly within Node.js (e.g., `stream.Readable.toWeb()` since Node.js v17), this package is largely superseded. Its development is effectively halted, and users are encouraged to explore native Node.js APIs or more actively maintained alternatives for stream interoperability. The module was written in ES5 and was compatible with bundlers like Browserify and Webpack without needing transpilation.","status":"deprecated","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/xuset/readable-stream-node-to-web","tags":["javascript","readable","stream","readablestream","node","web","whatwg"],"install":[{"cmd":"npm install readable-stream-node-to-web","lang":"bash","label":"npm"},{"cmd":"yarn add readable-stream-node-to-web","lang":"bash","label":"yarn"},{"cmd":"pnpm add readable-stream-node-to-web","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module. While bundlers typically enable this ESM syntax via interop, the package itself is not native ESM and may behave differently in pure ESM Node.js environments.","wrong":"import { nodeToWebStream } from 'readable-stream-node-to-web';","symbol":"nodeToWebStream","correct":"import nodeToWebStream from 'readable-stream-node-to-web';"},{"note":"This is the original and intended CommonJS usage as demonstrated in the package's README.","symbol":"nodeToWebStream","correct":"const nodeToWebStream = require('readable-stream-node-to-web');"}],"quickstart":{"code":"import { Readable } from 'node:stream';\nimport nodeToWebStream from 'readable-stream-node-to-web';\n\n// Create a mock Node.js Readable stream\nclass MockNodeReadable extends Readable {\n  constructor(dataArray) {\n    super();\n    this.data = [...dataArray];\n  }\n\n  _read() {\n    if (this.data.length) {\n      this.push(this.data.shift());\n    } else {\n      this.push(null);\n    }\n  }\n}\n\nconst nodeStream = new MockNodeReadable(['Hello', ' ', 'World', '!']);\nconst webStream = nodeToWebStream(nodeStream);\n\n// Consume the web stream\nasync function consumeWebStream() {\n  const reader = webStream.getReader();\n  let result = '';\n  while (true) {\n    const { done, value } = await reader.read();\n    if (done) {\n      break;\n    }\n    result += new TextDecoder().decode(value);\n  }\n  console.log('Consumed Web Stream:', result);\n}\n\nconsumeWebStream();","lang":"javascript","description":"Demonstrates converting a mock Node.js Readable stream to a WHATWG ReadableStream and then consuming its data using a web stream reader."},"warnings":[{"fix":"Consider using native Node.js stream conversion utilities like `stream.Readable.toWeb()` (available since Node.js v17) or `stream.Readable.fromWeb()`. Alternatively, explore more actively maintained libraries such as `node-readable-to-web-readable-stream` for robust stream interoperability.","message":"This package has not been updated in approximately nine years (last published August 2017). It is no longer actively maintained and is considered superseded.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"For native ESM environments, explicitly use dynamic `import()` or switch to a native ESM-first library that provides this functionality. If bundling, ensure your bundler is configured for CJS interop.","message":"The package is a CommonJS module. While bundlers typically handle interop, direct usage in pure ESM Node.js environments might require specific loader configurations or the `require` syntax.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Node.js v17+ and use `import { Readable } from 'node:stream'; const webStream = nodeStream.toWeb();`. This leverages core Node.js functionality without external dependencies.","message":"Node.js v17 and later include built-in `stream.Readable.toWeb()` and `stream.Writable.fromWeb()` methods, offering a native and often more performant way to convert between Node.js and Web Streams. Using this package introduces an unnecessary dependency for newer Node.js versions.","severity":"gotcha","affected_versions":"<1.0.0 || >=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const nodeToWebStream = require('readable-stream-node-to-web');` for CommonJS. If in an ESM file, bundlers might support `import nodeToWebStream from 'readable-stream-node-to-web';` but direct Node.js ESM might need careful handling or a switch to native APIs.","cause":"Attempting to use `require('readable-stream-node-to-web')` in a way that expects a named export, or in a pure ESM context without proper interop.","error":"TypeError: require(...) is not a function"},{"fix":"Ensure Node.js is v17 or newer for native `.toWeb()` support. If using an older Node.js, you must use this `readable-stream-node-to-web` package (or a similar alternative) for conversion. For TypeScript, ensure your `tsconfig.json` targets a Node.js version that includes these types or add a custom declaration file.","cause":"Attempting to use `nodeStream.toWeb()` on a Node.js `Readable` stream in an older Node.js version (<v17) or without TypeScript type declarations for `toWeb`.","error":"Property 'toWeb' does not exist on type 'Readable'"}],"ecosystem":"npm"}