awslabs / awslabs/llrt

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

Open
#522 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
8.8k
Forks
393
Avg merge
1d 11h
Merged PRs (30d)
45

Description

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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the globalThis.ReadableStream construction and inspect how the stream module exposes WHATWG ReadableStream versus Node.js Readable. Compare that behavior with the node:stream exports and Duplex.toWeb() conversion described in the report. Done means the supported behavior and required usage are clarified or the reported mismatch is resolved and covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.