Skip to content

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

Closed
restatedev/sdk-typescript
#426
@sosoba

Description

@sosoba

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 this condition:

if (typeof streamWritable?._writableState !== 'object') {

is too heavy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.good first issueIssues that are suitable for first-time contributors.httpIssues or PRs related to the http subsystem.streamIssues and PRs related to the stream subsystem.web streams

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions