SyntaxError: Could not find export 'ReadableStream' in module 'stream'
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.
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.
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.
@guest271314 WHATWG webstreams are no implementeed (partially). They are however not integrated in fetch for instance.