Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readline node not working with async iterator syntax #2535

Closed
babymum7 opened this issue Apr 2, 2023 · 6 comments
Closed

readline node not working with async iterator syntax #2535

babymum7 opened this issue Apr 2, 2023 · 6 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@babymum7
Copy link

babymum7 commented Apr 2, 2023

What version of Bun is running?

0.5.8

What platform is your computer?

Darwin 22.4.0 x86_64 i386

What steps can reproduce the bug?

readline node not working with async iterator syntax while createReadStream dose

What is the expected behavior?

Should work just like with Node

What do you see instead?

1 | import fs from 'node:fs';
2 | import readline from 'node:readline';
3 |
4 | for await (const line of readline.createInterface({
                     ^
TypeError: undefined is not an object (evaluating 'line of readline.createInterface({
  input: fs.createReadStream("./2023-04-01.csv")
})')

Additional information

minimal snippet

import fs from 'node:fs';
import readline from 'node:readline';

for await (const line of readline.createInterface({
  input: fs.createReadStream('./2023-04-01.csv'),
})) {
  console.log(line);
}
@babymum7 babymum7 added the bug Something isn't working label Apr 2, 2023
@ThatOneBro
Copy link
Contributor

ThatOneBro commented Apr 2, 2023

I'm actually just about done fixing this, the problem was our node:events.on was out of spec and didn't return an async iterator, which readline's async iterator uses internally. Once I finish testing that, this issue should be resolved too

Related: #2187

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Apr 3, 2023
@eL1x00r
Copy link

eL1x00r commented Jan 14, 2024

when fix

@zavan
Copy link

zavan commented Feb 3, 2024

This works on bun 1.0.25:

import { createReadStream } from "node:fs";
import { createInterface } from "node:readline/promises";

const stream = createReadStream('file.csv');
const rl = createInterface({ input: stream });

for await (const line of rl) {
  console.log(line);
}

Edit: Nope. Only reads 3 lines.

@Electroid
Copy link
Contributor

It now appears to only read the first line.

@mvdkwast
Copy link

It now appears to only read the first line.

Confirmed in 1.0.26

@Jarred-Sumner
Copy link
Collaborator

This was fixed in Bun v1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

7 participants