{"id":13354,"library":"iso-random-stream","title":"Isomorphic Random Bytes Stream","description":"iso-random-stream provides an isomorphic (Node.js and browser compatible) readable stream for cryptographic random bytes. In Node.js environments, it leverages `crypto.randomBytes`, while in browsers, it utilizes `Crypto.getRandomValues()` for secure randomness. The package is currently at version 2.0.2, primarily releasing bug fixes and minor updates after a significant breaking change in version 2.0.0. The v2.0.0 release refactored the internal implementation, removed an explicit `Buffer` dependency, and introduced first-party TypeScript type definitions. Unlike some alternatives, it offers a streaming interface, which is beneficial for generating large quantities of random data without consuming excessive memory upfront.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/hugomrdias/iso-random-stream","tags":["javascript","stream","random","bytes","isomorphic","node","browser","typescript"],"install":[{"cmd":"npm install iso-random-stream","lang":"bash","label":"npm"},{"cmd":"yarn add iso-random-stream","lang":"bash","label":"yarn"},{"cmd":"pnpm add iso-random-stream","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v2.0.0, `randomStream` is a named export. Despite conflicting v2.0.0 release notes, it is not a default export.","wrong":"import randomStream from 'iso-random-stream';","symbol":"randomStream","correct":"import { randomStream } from 'iso-random-stream';"},{"note":"The `randomStream` function is a named export, requiring destructuring for CommonJS.","wrong":"const randomStream = require('iso-random-stream');","symbol":"randomStream (CommonJS)","correct":"const { randomStream } = require('iso-random-stream');"}],"quickstart":{"code":"import { randomStream } from 'iso-random-stream';\nimport { Writable } from 'stream';\n\n// Create a stream that produces 100 random bytes\nconst stream = randomStream(100);\n\n// Create a writable stream to consume the bytes and print them as hex\nconst consumer = new Writable({\n  write(chunk, encoding, callback) {\n    console.log(`Received chunk (${chunk.length} bytes):`, chunk.toString('hex'));\n    callback();\n  }\n});\n\n// Pipe the random bytes stream to the consumer\nstream.pipe(consumer);\n\n// Listen for the 'finish' event when all bytes have been generated and consumed\nconsumer.on('finish', () => {\n  console.log('Finished generating and consuming 100 random bytes.');\n});","lang":"typescript","description":"Demonstrates how to create a readable stream of 100 random bytes and pipe it to a writable stream for consumption."},"warnings":[{"fix":"Review how you handle stream chunks, especially if you had explicit `Buffer` checks or transformations. Update bundler configurations to remove any `buffer` polyfills that were previously required for this library.","message":"Version 2.0.0 introduced significant breaking changes. Internally, the direct dependency on the `buffer` module was removed. This affects how random data is processed and potentially how consumers handle the stream's output if they relied on specific `Buffer` characteristics from prior versions. Output is now typically `Uint8Array` via Node.js streams.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always use named imports: `import { randomStream } from 'iso-random-stream'` (ESM) or `const { randomStream } = require('iso-random-stream')` (CommonJS).","message":"The v2.0.0 release notes incorrectly state \"named exports removed.\" Despite this, `iso-random-stream` *continues* to use named exports (e.g., `randomStream`), as reflected in its current source code and documentation. Developers should continue to import `randomStream` as a named export.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Remove `@types/iso-random-stream` from your `devDependencies` in `package.json`.","message":"Version 2.0.0 introduced official TypeScript type definitions directly within the package. If you were previously using `@types/iso-random-stream` with v1.x, this external types package is no longer necessary and should be removed to avoid type conflicts.","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":"Ensure you are destructuring the named export: `const { randomStream } = require('iso-random-stream');` for CommonJS or `import { randomStream } from 'iso-random-stream';` for ESM.","cause":"Attempting to access `require('iso-random-stream').randomStream` without destructuring when the root export is not an object with a `randomStream` property, or if using a default import incorrectly.","error":"TypeError: Cannot read properties of undefined (reading 'randomStream')"},{"fix":"Ensure `randomStream` is imported as a named export: `import { randomStream } from 'iso-random-stream';`.","cause":"Incorrectly importing `randomStream` as a default export in an environment where it expects a named export, common in TypeScript or transpiled JavaScript.","error":"TypeError: iso_random_stream_1.randomStream is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null}