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

SyntaxError: Could not find export 'ReadableStream' in module 'stream' #522

Open
guest271314 opened this issue Aug 4, 2024 · 2 comments

Comments

@guest271314
Copy link

For disambiguity, what I'm referring to herein is WHATWG ReadableStream https://streams.spec.whatwg.org/#rs-class, not Node.js-specific Readable

When you do this

console.log(ReadableStream);

this is printed

[class: ReadableStream]

However, when trying to construct a ReadableStream

let z = 0;
const readable = new globalThis.ReadableStream({
  pull(c) {
    if (z === 5) {
      c.close();
    }
    c.enqueue(new Uint8Array([z]));
    ++z;
  }
});

this error is thrown

[class: ReadableStream]
Error: ReadableStream is not supported via global scope. Enable this by adding this to your code:
	import { ReadableStream } from "stream";
	globalThis.ReadableStream = ReadableStream;

Node.js Readable is not the same as WHATWG ReadableStream, and is not exported by "node:stream"

import * as streams from "node:stream";
console.log(streams);
{
  Duplex: [function: Duplex],
  PassThrough: [function: PassThrough],
  Readable: [function: Readable],
  Stream: [function: Stream],
  Transform: [function: Transform],
  Writable: [function: Writable],
  default: [function: Stream],
  finished: [function: finished],
  pipeline: [function: pipeline]
}

Duplex.toWeb() does convert a Node.js-specific Readable to a WHATWG ReadableStream. We shouldn't need to do that if WHATWG ReadableStream is defined globally.

This needs clarifying.

@Sytten
Copy link
Contributor

Sytten commented Aug 4, 2024

Streams is very much a WIP, the ReadableStream currently present is kinda of hack that only works for places where it is used in rust.

@guest271314
Copy link
Author

If the real WHATWG ReadableStream is not implemented it probably shouldn't be exposed, especially if the class is exposed, yet the runtime claims it's not a global. Doesn't make sense, to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants