Error Knowledge Base NPM EPIPE

npm ERR! code EPIPE

npm tried to write to stdout/stderr but the output stream was closed (broken pipe / EPIPE).

Affected versions: All supported npm versions.

What This Error Means

npm tried to write to stdout/stderr but the output stream was closed (broken pipe / EPIPE).

How to Fix It

  1. If you are piping output, remove the pipe and run npm directly (do not pipe to head/tail).
  2. If this happens only in CI, try npm ci instead of npm install (requires package-lock.json).
  3. Compare Node/npm versions between local and CI: node -v and npm -v.
  4. Retry with less output: npm --silent (or remove verbose logging).
  5. 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

  • 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).

How to Verify

  1. Re-run the same command without piping output and confirm EPIPE is gone.
  2. If you switched to npm ci, confirm the install completes reliably in CI.

Manual output and pipe checks

  1. Check whether the failing command is being run with output piping or a log wrapper.
  2. Re-run interactively (or via SSH) on the same machine and compare behavior.

Common CLI Output

npm ERR! code EPIPE
errorHandler({ errno: 'EPIPE' })
if (er.errno === 'EPIPE') {

How npm writes output

  1. EPIPE is a generic OS error that means a write was attempted on a closed pipe or socket.
  2. In practice, this usually happens when stdout/stderr is closed by the parent process while npm is logging.

Prevention Tips

  • Prefer npm ci in CI for clean deterministic installs.
  • Avoid piping npm output to commands that terminate early.
  • Keep Node and npm versions consistent between environments.

Where This Can Be Triggered

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)

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list