Node "Error: write EPIPE" in CI - Handle the Broken Pipe
EPIPE means your process wrote to a pipe whose reader has gone away. In CI it often happens when stdout is piped to a command that exits early, like head.
What this error means
A node process throws Error: write EPIPE, frequently from process.stdout, when the reader of a pipe closes before all output is written.
node
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3) {
errno: -32, code: 'EPIPE', syscall: 'write'
}Common causes
A downstream reader closed the pipe early
Piping node output into a command like head that exits after a few lines closes the read end, so further writes hit EPIPE.
Writing to a socket the peer already closed
The remote end disconnected, and a continued write to that stream raises EPIPE.
How to fix it
Handle the stream error
- Attach an error listener to the writable stream.
- Exit cleanly on EPIPE instead of letting it become an uncaught exception.
JavaScript
process.stdout.on('error', (err) => {
if (err.code === 'EPIPE') process.exit(0);
});Avoid truncating pipes in CI
- Remove pipes that close early (head, less) from CI commands.
- Write full output to a file or let it complete.
How to prevent it
- Attach error handlers to long-lived writable streams, avoid piping CI output through early-exiting readers, and treat EPIPE as a normal shutdown condition.
Related guides
Node "spawn ENOENT" for a Child Process in CI - Fix the Missing ExecutableFix the Node.js "spawn ENOENT" child-process error in CI by installing the missing executable or correcting t…
Node "process.exit called with code 1" Fails the Job in CI - Trace the CauseFix CI jobs failing on a Node.js process.exit(1) by finding the deliberate exit call and addressing the condi…
Node EADDRINUSE "address already in use" for a Test Server in CI - Fix Port ConflictsFix the Node.js EADDRINUSE "address already in use" error for a test server in CI by closing the previous lis…