Skip to content

stream: using an async iterator on a pipeline works on v18 but in v19 needs Readable.from(asyncItFn) #46141

Closed
@ErickWendel

Description

@ErickWendel

Version

19.3

Platform

darwin

Subsystem

No response

What steps will reproduce the bug?

The code below works on v18.13.0 but crashes on v19.3.0

import { pipeline } from 'node:stream/promises'
async function* myCustomReadable() {
    yield Buffer.from(`tick: ${new Date().toISOString()}`)
}

async function* myCustomWritable(stream) {
  for await (const chunk of stream) {
    console.log(chunk.toString())
  }
}

await pipeline(
  myCustomReadable,
  myCustomWritable,
)
node:internal/streams/readable:192
  const isDuplex = this instanceof Stream.Duplex;
                        ^

TypeError: Right-hand side of 'instanceof' is not an object
    at PassThrough.Readable (node:internal/streams/readable:192:25)
    at PassThrough.Duplex (node:internal/streams/duplex:58:12)
    at PassThrough.Transform (node:internal/streams/transform:106:10)
    at new PassThrough (node:internal/streams/passthrough:42:13)
    at pipelineImpl (node:internal/streams/pipeline:280:20)
    at node:stream/promises:28:5
    at new Promise (<anonymous>)
    at pipeline (node:stream/promises:17:10)
    at file:///Users/erickwendel/Downloads/projetos/cursos/mastering-streams/mastering-streams-code/example.mjs:12:7
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v19.3.0

but it works if explicitly convert it to a Readable

await pipeline(
  Readable.from(myCustomReadable()),
  myCustomWritable,
)

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

TypeError: Right-hand side of 'instanceof' is not an object

Additional information

@nodejs/streams @nodejs/tooling

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions