oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.88k stars 2.74k forks source link

`TypeError: undefined is not a function` when using async iterator on `TransformStream` #3859

Closed vjpr closed 1 year ago

vjpr commented 1 year ago

What version of Bun is running?

0.7.1

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

import {spawn} from 'node:child_process'
import {Readable} from 'node:stream'

let child
let webStream

if (global.Bun) {
  child = Bun.spawn(['echo'], ['1'])
  webStream = child.stdout
} else {
  child = spawn('echo', [1])
  webStream = Readable.toWeb(child.stdout)
}

const transform = new TransformStream({
  transform(chunk, controller) {
    controller.enqueue(1)
  }
})

const stream = webStream.pipeThrough(transform)

for await (const x of stream) {
  console.log(x)
}

What is the expected behavior?

No error

node ./index.js
1

What do you see instead?

bun ./index.js
1
TypeError: undefined is not a function

Additional information

It would be nice to have a stack trace for this kind of thing too...hard to tell if my own code or not.

vjpr commented 1 year ago

Doesn't happen in 0.7.0 stable. Regression in latest canary.

Jarred-Sumner commented 1 year ago

We haven't implemented async iterables for TransformStream yet. I think that's the cause of the issue. I do see another bug though

Jarred-Sumner commented 1 year ago

Oh I misread, nothing to do with async iterator on transform streams

Fixed in f2983e50b7004277800a14c4bf9371906884693c