Cannot pipe into a stream that is not writable
Production Risk
Low — caught immediately; fix by providing the correct stream type.
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.
- 1Passing a Readable stream as the destination of pipe()
- 2Passing a plain object or non-stream as the pipe destination
- 3Passing a stream that has already been destroyed
Triggered when pipe() validates the destination and finds it is not a Writable stream.
const { Readable } = require('stream');
const src = Readable.from(['a', 'b']);
const notWritable = new Readable({ read() {} }); // Readable, not Writable
src.pipe(notWritable); // throwsexpected 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
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.
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_PIPEtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_stream_cannot_pipe(...args) {
// validate args here
return performOperation(...args)
}✕ Pipe to a Readable stream or plain object
Only Writable (and Transform) streams can be pipe destinations.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev