diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 0e844d01200751..7e2ba628ac8889 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -101,11 +101,17 @@ function newWritableStreamFromStreamWritable(streamWritable) { // here because it will return false if streamWritable is a Duplex // whose writable option is false. For a Duplex that is not writable, // we want it to pass this check but return a closed WritableStream. - if (typeof streamWritable?._writableState !== 'object') { + const checkIfWritable = + streamWritable && + typeof streamWritable?.write === 'function' && + typeof streamWritable?.on === 'function' && + !streamWritable?._readableState; + if (!checkIfWritable) { throw new ERR_INVALID_ARG_TYPE( 'streamWritable', 'stream.Writable', - streamWritable); + streamWritable + ); } if (isDestroyed(streamWritable) || !isWritable(streamWritable)) {