node icon indicating copy to clipboard operation
node copied to clipboard

http.ServerResponse is not an instance of stream.Writable?

Open sosoba opened this issue 1 year ago • 0 comments

Version

18.7.0

Platform

Microsoft Windows NT 10.0.19044.0 x64

Subsystem

stream

What steps will reproduce the bug?

import { createServer } from 'node:http';
import { Writable } from 'node:stream';
import { once } from 'node:events';

const server = createServer(async (req, nodeStreamResponse) => {
  const webStreamResponse = Writable.toWeb(nodeStreamResponse);
});
server.listen({ port: 8080 });
await once(server, 'listening');
await fetch('http://localhost:8080');

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

According to the documentation:

Class: http.ServerResponse extends http.OutgoingMessage Class: http.OutgoingMessage extends Stream

This means that ServerResponse fulfilling the contract Writable.toWeb.

What do you see instead?

TypeError [ERR_INVALID_ARG_TYPE]: The "streamWritable" argument must be an stream.Writable. Received an instance of ServerResponse
    at new NodeError (node:internal/errors:387:5)
    at Object.newWritableStreamFromStreamWritable (node:internal/webstreams/adapters:99:11)
    at Writable.toWeb (node:internal/streams/writable:926:27)  

Additional information

Maybe the control in function Writable.toWeb is too strong?

sosoba avatar Aug 09 '22 10:08 sosoba