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.
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.
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 installIn 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.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm