What This Error Means
npm hit EPIPE because it tried to write output to a closed pipe or terminated process, often in CI logs or shell pipelines.
Read this as a precise clue about which part of the workflow broke first. Once you know the failing layer, the fix path gets much shorter.
How to Fix It
The fastest fixes here come from checking the immediate failing layer before you change anything unrelated. Make one correction at a time and re-test from the same environment.
If you are piping output, remove the pipe and run npm directly (do not pipe to head/tail).
If this happens only in CI, try npm ci instead of npm install (requires package-lock.json).
Compare Node/npm versions between local and CI:node -v and npm -v
Retry with less output:npm --silent (or remove verbose logging).
If your CI runs as root, and lifecycle scripts are involved, test with npm install --unsafe-perm (CI-only, understand the risk).
Why It Happens
There are usually a few repeatable root causes behind this message. Narrowing them down early prevents a lot of trial-and-error.
The command output is being piped to another process that exits early (example:npm ... | head).
A CI runner/log wrapper closed the output stream while npm was still writing logs. The process was interrupted while writing output (less common, but possible).
Verify the Fix
Re-run the same command without piping output and confirm EPIPE is gone, and if you switched to npm ci, confirm the install completes reliably in CI.
Manual output and pipe checks
Check whether the failing command is being run with output piping or a log wrapper, and re-run interactively (or via SSH) on the same machine and compare behavior.
Examples
npm ERR! code EPIPE
errorHandler({ errno: 'EPIPE' })
if (er.errno === 'EPIPE') { How npm writes output
EPIPE is a generic OS error that means a write was attempted on a closed pipe or socket. In practice, this usually happens when stdout/stderr is closed by the parent process while npm is logging.
Prevent It From Coming Back
To prevent this, prefer npm ci in CI for clean deterministic installs, avoid piping npm output to commands that terminate early, and keep Node and npm versions consistent between environments.
Docs and source code
github.com/npm/cli/blob/417daa72b09c5129e7390cd12743ef31bf3ddb83/lib/commands/completion.js
Open-source npm CLI code path where this error is raised. - GitHub
// can never ever work on OS X.
// TODO Ignoring coverage, see 'non EPIPE errors cause failures' test.
/* istanbul ignore next */
if (er.errno === 'EPIPE') {
res()
} else {
rej(er)