ERR_STREAM_CANNOT_PIPE
Node.jsERRORNotableStreamHIGH confidence

Cannot pipe into a stream that is not writable

Production Risk

Low — caught immediately; fix by providing the correct stream type.

What this means

Thrown when readable.pipe() is called with a destination that is not a Writable stream. The destination must implement the Writable interface (with write and end methods) for pipe() to function.

Why it happens
  1. 1Passing a Readable stream as the destination of pipe()
  2. 2Passing a plain object or non-stream as the pipe destination
  3. 3Passing a stream that has already been destroyed
How to reproduce

Triggered when pipe() validates the destination and finds it is not a Writable stream.

trigger — this will error
trigger — this will error
const { Readable } = require('stream');
const src = Readable.from(['a', 'b']);
const notWritable = new Readable({ read() {} }); // Readable, not Writable
src.pipe(notWritable); // throws

expected output

Error [ERR_STREAM_CANNOT_PIPE]: Cannot pipe, not writable

Fix

Pipe to a Writable or Transform stream

WHEN Always — ensure the pipe destination is Writable

Pipe to a Writable or Transform stream
const { Readable, Writable } = require('stream');
const src = Readable.from(['hello', ' world']);
const dst = new Writable({
  write(chunk, enc, cb) { process.stdout.write(chunk); cb(); }
});
src.pipe(dst);

Why this works

Providing a proper Writable as the destination satisfies the pipe() type check.

Code examples
Triggerjs
const { Readable } = require('stream');
const src = Readable.from(['a', 'b']);
const notWritable = new Readable({ read() {} }); // Readable, not Writable
src.pipe(notWritable); // throws  // this triggers ERR_STREAM_CANNOT_PIPE
Handle in try/catchjs
try {
  // operation that may throw ERR_STREAM_CANNOT_PIPE
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_STREAM_CANNOT_PIPE') {
    console.error('ERR_STREAM_CANNOT_PIPE:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_stream_cannot_pipe(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Pipe to a Readable stream or plain object

Only Writable (and Transform) streams can be pipe destinations.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors