The HTTP 502 Bad Gateway error occurs when an intermediate server (like a CDN or proxy) receives an invalid response from the npm registry. This is typically a temporary infrastructure issue.
HTTP 502 indicates that a gateway or proxy server received an invalid response from an upstream server. In npm's case, this usually means the CDN or load balancer couldn't get a proper response from the actual registry servers. This is almost always a temporary infrastructure issue and not something you can fix directly. It often affects only certain geographic regions or CDN edge locations.
Look for known issues:
curl -s https://status.npmjs.org/api/v2/status.json | jq
# Or visit
open https://status.npmjs.org502 errors are often transient:
# Simple retry
npm install
# With delay
for i in 1 2 3; do npm install && break || sleep 30; doneChange DNS resolution path:
# Use different DNS
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Or use VPN to change geographic routingTemporarily switch registry:
npm install --registry https://registry.npmmirror.comThis bypasses the main npm CDN.
Identify where the issue is:
# Trace the route
traceroute registry.npmjs.org
# Test direct connection
curl -v https://registry.npmjs.org/lodashWork offline if possible:
# If packages are in cache
npm install --prefer-offline
# Or use local proxy with cached packagesnpm uses Fastly CDN which has global edge locations. 502 errors often indicate issues at specific edge nodes. Using a VPN to appear from a different region can sometimes route around problem nodes. For production systems, maintain a warm package cache and consider using a caching proxy. Monitor npm status via their API for automated alerting.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error