How to fix npm ERR! 504 Gateway Timeout in npm
The HTTP 504 Gateway Timeout error occurs when the npm registry doesn't respond in time. This indicates network latency issues, registry overload, or proxy timeout configurations.
Quick fix
Fixes npm ERR! 504 Gateway Timeout
# Test latency
ping registry.npmjs.org
# Test download speed
curl -o /dev/null -w "%{speed_download}" https://registry.npmjs.org/lodash- Test network speed to registry
- Increase npm timeouts
- Reduce concurrent connections
- Use npm mirror closer to you
# Test latencyping registry.npmjs.org# Test download speedcurl -o /dev/null -w "%{speed_download}" https://registry.npmjs.org/lodashnpm ERR! 504 Gateway Timeout
What this error means
HTTP 504 indicates that a gateway or proxy didn't receive a timely response from the upstream server. In npm's context, this means the CDN or intermediate proxy timed out waiting for a response from the registry backend. This can be caused by slow network connections, registry overload, or aggressive timeout settings on intermediate proxies.
Typical symptoms
- npm operations hang then fail with 504
- Slow network connection to registry
- Large packages fail more often
- Error after long wait time
- Corporate proxy timeout
- Inconsistent failures
Common causes
- Slow network connection
- Registry under heavy load
- Proxy timeout too short
- Large package download timing out
- VPN adding latency
- Geographic distance to registry
- Network congestion
How to fix "npm ERR! 504 Gateway Timeout"
Check latency and throughput:
# Test latency
ping registry.npmjs.org
# Test download speed
curl -o /dev/null -w "%{speed_download}" https://registry.npmjs.org/lodashAllow more time for slow connections:
npm config set fetch-timeout 600000
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000Fewer parallel downloads:
npm config set maxsockets 3This reduces load on slow connections.
Reduce latency with regional mirror:
# For China
npm config set registry https://registry.npmmirror.com
# For Europe (use company mirror if available)If behind corporate proxy:
1. Request IT increase proxy timeout
2. Typical timeout should be 5+ minutes
3. Or use local npm proxy that has better timeout handling
For persistently failing packages:
# Install problematic package separately
npm install large-package --timeout 600000
# Then install rest
npm installAdvanced notes
In CI/CD on cloud providers, choose regions with good connectivity to npm CDN (US-East typically best). For air-gapped or high-latency environments, sync packages to a local registry. Consider using pnpm which has more efficient network usage. Monitor npm network requests to identify consistently slow packages.
Frequently asked questions
- What does "npm ERR! 504 Gateway Timeout" mean?
- HTTP 504 indicates that a gateway or proxy didn't receive a timely response from the upstream server. In npm's context, this means the CDN or intermediate proxy timed out waiting for a response from the registry backend. This can be caused by slow network connections, registry overload, or aggressive timeout settings on intermediate proxies.
- How do I fix "npm ERR! 504 Gateway Timeout"?
- The HTTP 504 Gateway Timeout error occurs when the npm registry doesn't respond in time. This indicates network latency issues, registry overload, or proxy timeout configurations.
- What causes "npm ERR! 504 Gateway Timeout"?
- Slow network connection Registry under heavy load Proxy timeout too short
- Is the "npm ERR! 504 Gateway Timeout" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐