{"id":"bd1c2d8a7373d3b7","repo":"sindresorhus/is","slug":"expected-value-which-is-node-js-stream-received","errorCode":null,"errorMessage":"Expected value which is `Node.js Stream`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Node\\.js Stream`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1737,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('native Promise', value));\n\t}\n}\n\nexport function assertNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative integer', value));\n\t}\n}\n\nexport function assertNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('negative number', value));\n\t}\n}\n\nexport function assertNodeStream(value: unknown, message?: string): asserts value is NodeStream {\n\tif (!isNodeStream(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Node.js Stream', value));\n\t}\n}\n\nexport function assertNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[], message?: string): asserts value is [Item, ...Item[]] {\n\tif (!isNonEmptyArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty array', value));\n\t}\n}\n\nexport function assertNonEmptyMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value> {\n\tif (!isNonEmptyMap(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty map', value));\n\t}\n}\n\nexport function assertNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown, message?: string): asserts value is Record<Key, Value> {\n\tif (!isNonEmptyObject(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty object', value));","sourceCodeStart":1719,"sourceCodeEnd":1755,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1719-L1755","documentation":"Thrown by `assertNodeStream()` (source/index.ts:1735) when `isNodeStream()` fails; that predicate duck-types the value as `isObject(value) && isFunction(value.pipe) && !isObservable(value)`. So it needs an object with a callable `pipe` method that is not an Observable — it does not require inheriting from Node's stream classes.","triggerScenarios":"Calling `assertNodeStream()` with a WHATWG web stream (ReadableStream — has `pipeTo`/`pipeThrough`, not `pipe`), a Buffer or string of the full content, an RxJS Observable (explicitly excluded even if it has pipe), an async iterator, or a closed/undefined stream variable.","commonSituations":"The fetch-API migration is the big one: `fetch()` response bodies and many modern APIs (undici, Node 18+ `fs.openAsBlob`, web streams) return WHATWG streams, not Node streams. Also passing RxJS Observables (whose `.pipe` exists but is deliberately rejected), or file contents read eagerly instead of streamed.","solutions":["Convert web streams: `stream.Readable.fromWeb(webStream)` (Node 17+) before asserting.","Create a stream from in-memory data: `stream.Readable.from(bufferOrIterable)`.","For RxJS Observables, this assert rejects them by design — convert or use an Observable-aware path instead.","Verify the producer actually returned a stream (not undefined from an error path) before the assert site."],"exampleFix":"// before\nconst body = (await fetch(url)).body;\nassertNodeStream(body); // throws — WHATWG ReadableStream\n// after\nimport {Readable} from 'node:stream';\nconst body = Readable.fromWeb((await fetch(url)).body);\nassertNodeStream(body);","handlingStrategy":"type-guard","validationCode":"const {Stream} = require('node:stream');\nif (!(value instanceof Stream) && !(value && typeof value.pipe === 'function')) {\n  throw new TypeError('Expected a Node.js Stream');\n}","typeGuard":"const isNodeStream = (v: unknown): v is NodeJS.ReadableStream | NodeJS.WritableStream => v !== null && typeof v === 'object' && typeof (v as any).pipe === 'function';","tryCatchPattern":null,"preventionTips":["Web streams (ReadableStream from fetch) are NOT Node streams — bridge with stream.Readable.fromWeb / stream.Readable.toWeb","In browser bundles Node streams don't exist; gate stream-based code paths by runtime environment","Prefer node:stream utilities (isReadable, isWritable in modern Node) for finer-grained checks than duck-typed .pipe"],"tags":["stream","node","type-assertion"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}