How to fix npm ERR! code EPIPE npm ERR! errno EPIPE npm ERR! syscall write in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 214 views

The npm EPIPE error occurs when npm tries to write data to a pipe or stream that has been closed. This typically happens due to network issues, Node.js version bugs, or stream mismatches during package installation.

Quick fix

Fixes EPIPE

# Wait a moment and retry
npm install

# Or with npm ci for clean installs
npm ci
  1. Retry the npm command
  2. Clear the npm cache
  3. Check your Node.js version
  4. Use the --no-audit flag
npm — error
# Wait a moment and retry
npm install
# Or with npm ci for clean installs
npm ci
npm ERR! code EPIPE
npm ERR! errno EPIPE
npm ERR! syscall write

What this error means

The "EPIPE" error in npm stands for "Error: Pipe" and is a POSIX error code indicating a broken pipe or socket connection. This error occurs when npm attempts to write data to a stream or pipe that no longer has a process reading from it. When you run `npm install` or `npm ci`, npm communicates with the npm registry over the network and processes data through various internal streams. If any of these connections are unexpectedly closed—whether due to network instability, process termination, or bugs in Node.js itself—npm cannot complete its write operation, resulting in the EPIPE error. This error became particularly common in October 2022 when Node.js v16.18.0 introduced a breaking change that affected npm in CI/CD environments. The error can also occur due to memory leaks in Node applications, corporate proxy issues, or when the npm registry connection is interrupted.

Typical symptoms

  • npm install or npm ci fails with 'npm ERR! code EPIPE' message
  • Error occurs intermittently, sometimes succeeding on retry
  • CI/CD pipeline builds fail randomly during package installation
  • Error appears after upgrading Node.js version
  • Installation works locally but fails in Docker or CI environments

Common causes

  1. Unstable network connection causing the registry connection to drop
  2. Node.js version bug (notably v16.18.0) breaking npm ci behavior
  3. Corporate proxy interrupting or resetting connections
  4. Docker or CI environment memory/resource constraints
  5. Corrupted npm cache causing stream processing issues
  6. Registry timeout or rate limiting closing connections prematurely

How to fix "npm ERR! code EPIPE npm ERR! errno EPIPE npm ERR! syscall write"

1Retry the npm command

Since EPIPE errors are often intermittent due to network issues, a simple retry may succeed:

bash
# Wait a moment and retry
npm install

# Or with npm ci for clean installs
npm ci

If the error persists across multiple attempts, proceed to the other solutions.

2Clear the npm cache

A corrupted cache can cause stream processing issues. Clear it and retry:

bash
# Clear the npm cache forcefully
npm cache clean --force

# Verify the cache is cleared
npm cache verify

# Now retry installation
npm install

This removes all cached packages and metadata, forcing npm to download fresh data.

3Check your Node.js version

Certain Node.js versions, particularly v16.18.0, introduced bugs that cause EPIPE errors:

bash
# Check your current Node.js version
node --version

# If using v16.18.0, downgrade or upgrade
nvm install 16.17.1
nvm use 16.17.1

# Or upgrade to a newer patched version
nvm install 18
nvm use 18

If you're using Docker, update your base image:

dockerfile
# Instead of node:latest or node:16
FROM node:18-alpine
# Or pin to a known working version
FROM node:16.17.1-buster
4Use the --no-audit flag

The audit step can trigger EPIPE errors in some environments. Bypass it:

bash
# Skip the audit during installation
npm ci --no-audit

# Or for regular install
npm install --no-audit

Note: This skips security vulnerability checks, so use it only as a workaround and consider running npm audit separately afterward.

5Check network and proxy settings

Network issues, especially behind corporate proxies, can cause EPIPE:

bash
# Test connectivity to npm registry
ping registry.npmjs.org

# Check current proxy settings
npm config get proxy
npm config get https-proxy

# Set proxy if behind a corporate firewall
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Or in Dockerfile
RUN npm config set proxy $HTTP_PROXY && \
    npm config set https-proxy $HTTPS_PROXY && \
    npm install

If you're not using a proxy, ensure these are unset:

bash
npm config delete proxy
npm config delete https-proxy
6Set HOME environment variable in CI/Docker

Some CI environments need the HOME variable set explicitly:

bash
# In your CI config or Dockerfile
export HOME=/root
npm install

Or in a Dockerfile:

dockerfile
ENV HOME=/root
RUN npm ci

In GitLab CI:

yaml
variables:
  HOME: "."

install_dependencies:
  script:
    - npm ci
7Increase npm timeout settings

If connections are timing out, increase npm's timeout values:

bash
# Increase network timeout (in milliseconds)
npm config set fetch-timeout 60000
npm config set fetch-retries 5

# Or use environment variables
export npm_config_fetch_timeout=60000
npm install

For CI environments, add these to your build configuration:

yaml
# GitHub Actions example
- run: |
    npm config set fetch-timeout 60000
    npm ci
8Clean workspace in CI (Jenkins, GitLab)

Corrupted workspace state can cause EPIPE. Clean it before installing:

bash
# Remove node_modules and lock file
rm -rf node_modules
rm -f package-lock.json

# Fresh install
npm install

In Jenkins, use the workspace cleanup plugin or:

groovy
cleanWs()

In GitLab CI, ensure fresh clones:

yaml
variables:
  GIT_STRATEGY: clone

Advanced notes

### Understanding EPIPE at the System Level

EPIPE is a POSIX signal (SIGPIPE) that occurs when a process attempts to write to a pipe whose read end has been closed. In the context of npm:

1. npm opens an HTTP connection to the registry
2. The registry streams package data
3. If the connection drops mid-transfer, the write end tries to continue
4. The OS signals EPIPE because nothing is reading anymore

### Node.js v16.18.0 Breaking Change

In October 2022, Node.js v16.18.0 changed how it handles certain I/O operations, which broke npm ci in CI/CD environments. The fix was released in later versions, but many CI pipelines using node:latest or node:16 Docker images were affected.

### Memory-Related EPIPE Errors

In constrained environments (CI runners, small Docker containers), npm can trigger EPIPE when:
- Memory limits cause the process to be killed mid-operation
- Swap space is exhausted
- Container OOM killer terminates child processes

To diagnose:

bash
# Check memory during npm install
npm install &
watch -n 1 'free -m'

### AWS CodeBuild Specific Fix

If you encounter EPIPE in AWS CodeBuild, invalidate the project cache:

bash
aws codebuild invalidate-project-cache --project-name your-project

Or configure the buildspec to not cache npm:

yaml
cache:
  paths: []  # Disable caching

### Programmatic Error Handling

If you're spawning npm from Node.js code, handle EPIPE errors:

javascript
const { spawn } = require('child_process');

const npm = spawn('npm', ['install']);

npm.stdout.on('error', (err) => {
  if (err.code === 'EPIPE') {
    console.log('Pipe closed, retrying...');
    // Implement retry logic
  }
});

process.stdout.on('error', (err) => {
  if (err.code === 'EPIPE') {
    process.exit(0);  // Graceful exit on pipe close
  }
});

Frequently asked questions

What does "EPIPE" mean?
The "EPIPE" error in npm stands for "Error: Pipe" and is a POSIX error code indicating a broken pipe or socket connection. This error occurs when npm attempts to write data to a stream or pipe that no longer has a process reading from it. When you run npm install or npm ci, npm communicates with the npm registry over the network and processes data through various internal streams.
How do I fix "EPIPE"?
The npm EPIPE error occurs when npm tries to write data to a pipe or stream that has been closed. This typically happens due to network issues, Node.js version bugs, or stream mismatches during package installation.
What causes "EPIPE"?
Unstable network connection causing the registry connection to drop Node.js version bug (notably v16.18.0) breaking npm ci behavior Corporate proxy interrupting or resetting connections
Is the "EPIPE" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading