You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hit b in the console to send a request (or use curl)
You will see the following error:
[wrangler:err] TypeError: This ReadableStream is disturbed (has already been read from), and cannot be used as a body.
at Object.fetch (file:///Users/vberchet/code/work/extends-readable/src/index.ts:80:15)
at fetchDispatcher (file:///Users/vberchet/code/work/extends-readable/.wrangler/tmp/bundle-IHVd6O/middleware-loader.entry.ts:54:17)
It originates in:
// Error with:// TypeError: This ReadableStream is disturbed (has already been read from), and cannot be used as a body.constreq=newRequest('http://example.com',{method: 'POST',body: Readable.toWeb(ic)});// Works//const req = new Request('http://example.com', { method: 'POST', body: ReadableStream.from(ic) });
You can see that the first snippet that used to work now error.
ic is an instance of IncomingMessage (local) < http.IncomingMessage (unenv) < Readable (workerd)
Note that before unjs/unenv#363 (2w ago), the Readable implementation was coming from unenv. It might explain why this code used to work.
Still I think { body: Readable.toWeb(ic) } should work and we should understand why it doesn't.
Other info:
I have tried to call Readable.isDisturbed(ic) right before the super constructor call and it returns false.
ref issue: #2746
^ this issue is about workerd streams not compatible with Node stream. The reason is that we want to stick to the specs while Node (/undici) does not.
In workerd, it is not possible to initialize the body with a
Readable
as in:We have used a workaround for NextJS:
{ body: Readable.toWeb(readable) }
The workaround stopped working following some updates in the Next adapter code base.
There is a repro in https://github.com/vicb/workerd-stream
npm i
npx wrangler dev
curl
)You will see the following error:
It originates in:
You can see that the first snippet that used to work now error.
ic is an instance of
IncomingMessage
(local) <http.IncomingMessage
(unenv) <Readable
(workerd)Note that before unjs/unenv#363 (2w ago), the
Readable
implementation was coming fromunenv
. It might explain why this code used to work.Still I think
{ body: Readable.toWeb(ic) }
should work and we should understand why it doesn't.Other info:
I have tried to call
Readable.isDisturbed(ic)
right before the super constructor call and it returnsfalse
.@jasnell could you please help investigate?
The text was updated successfully, but these errors were encountered: