{"record":{"id":"ddc4a788b778f1ec","repo":"denoland/deno","slug":"err-invalid-arg-type-ddc4a7","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"readableStream\" argument must be an instance of ReadableStream","messagePattern":"The \"readableStream\" argument must be an instance of ReadableStream","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/webstreams/adapters.js","lineNumber":65,"sourceCode":"}\n\n// Normalize a `writev` completion value to the first real error, or `undefined`\n// when every write succeeded. `Promise.all` fulfils with an array (one slot per\n// chunk, holes for successes), while a rejection or synchronous throw settles\n// with a single scalar error.\nfunction firstWritevError(error) {\n  if (Array.isArray(error)) {\n    return error.find((e) => e);\n  }\n  return error == null ? undefined : error;\n}\n\nfunction newStreamReadableFromReadableStream(\n  readableStream,\n  options = kEmptyObject,\n) {\n  if (!isReadableStream(readableStream)) {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"readableStream\",\n      \"ReadableStream\",\n      readableStream,\n    );\n  }\n\n  validateObject(options, \"options\");\n  const {\n    highWaterMark,\n    encoding,\n    objectMode = false,\n    signal,\n  } = options;\n\n  if (encoding !== undefined && !Buffer.isEncoding(encoding)) {\n    throw new ERR_INVALID_ARG_VALUE(encoding, \"options.encoding\");\n  }\n  validateBoolean(objectMode, \"options.objectMode\");","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/webstreams/adapters.js#L47-L83","documentation":"newStreamReadableFromReadableStream — the engine behind stream.Readable.fromWeb — accepts only a WHATWG ReadableStream (the global web class). A Node streams.Readable, a fetch Response, undefined, or any other object fails the brand check and throws ERR_INVALID_ARG_TYPE.","triggerScenarios":"Readable.fromWeb(fs.createReadStream('f')) (a Node stream, not a web stream); Readable.fromWeb(undefined); passing response instead of response.body; grabbing the wrong variable where both node and web variants exist.","commonSituations":"Bridging fetch/MCP/web APIs into Node stream consumers; direction confusion between toWeb (Node→web) and fromWeb (web→Node); web streams obtained from another realm/implementation.","solutions":["Pass a real web ReadableStream: Readable.fromWeb(response.body)","If the source is a Node stream, convert first with Readable.toWeb(nodeStream) — or just use the Node stream directly","Guard with 'x instanceof ReadableStream' (global web class) before calling"],"exampleFix":"// before\nconst readable = Readable.fromWeb(fs.createReadStream('data.txt')); // throws\n\n// after\nconst readable = fs.createReadStream('data.txt'); // already a Node Readable\n// web->node direction needs a web stream: Readable.fromWeb(response.body)","handlingStrategy":"type-guard","validationCode":"if (!(source instanceof ReadableStream)) {\n  throw new TypeError('Expected a WHATWG ReadableStream (use Readable.toWeb for Node streams)');\n}\nconst readable = Readable.fromWeb(source);","typeGuard":"const isWebReadableStream = (s) =>\n  typeof ReadableStream !== 'undefined' && s instanceof ReadableStream;","tryCatchPattern":null,"preventionTips":["Remember the direction: fromWeb is web→Node, toWeb is Node→web","Type bridge variables (webIn: ReadableStream) in TypeScript to catch mixups at compile time","fetch bodies are response.body, not response"],"tags":["web-streams","stream-adapters","node-compat","type-validation"],"backgroundTag":"web-stream-adapter-type-mismatch","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}