The E408 error occurs when npm's request to the registry exceeds the timeout limit, usually due to slow connections or registry latency. This prevents package installation or updates from completing.
npm ERR! code E408 is a 408 Request Timeout error that happens when npm tries to fetch a package from the registry but the request takes longer than the configured timeout period (default 30 seconds). This typically occurs during `npm install`, `npm update`, or `npm publish` operations when the registry server is slow to respond, your internet connection is unstable, or a large package metadata file exceeds the time limit. The error indicates that npm sent a request but didn't receive a response within the expected timeframe. Rather than hanging indefinitely, npm cancels the request and reports the timeout, allowing you to retry or adjust settings. This is a network-level issue, not a problem with your code or the package itself.
The quickest fix is to increase npm's timeout values to accommodate slower connections:
npm config set fetch-timeout 300000
npm config set fetch-retry-maxtimeout 120000
npm config set fetch-retry-mintimeout 20000These settings mean:
- fetch-timeout: 5 minutes (300000ms) for the entire request
- fetch-retry-maxtimeout: 2 minutes between retries
- fetch-retry-mintimeout: 20 seconds minimum before first retry
Alternatively, add these directly to ~/.npmrc:
fetch-timeout=300000
fetch-retry-maxtimeout=120000
fetch-retry-mintimeout=20000
fetch-retries=5Corrupted cache or lock files can cause timeouts. Remove the cache and local dependencies, then reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installThis forces npm to download fresh from the registry without using cached metadata that might be causing issues.
If the official npm registry is slow in your region, use a mirror. Popular alternatives include:
# Use npmmirror (good for Asia)
npm config set registry https://registry.npmmirror.com/
# Switch back to official registry
npm config set registry https://registry.npmjs.org/Mirrors often have better latency in specific regions and can significantly reduce timeout issues.
If you're on a corporate network, proxy settings might be missing or incorrect:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080If you don't need a proxy, remove these settings:
npm config delete proxy
npm config delete https-proxyYou can also check current settings with:
npm config listRun the install with verbose logging to identify which package is timing out:
npm install --verboseIf a specific package is the culprit, try installing it alone:
npm install package-name@latest --verboseCheck your network connectivity:
ping registry.npmjs.org
curl -I https://registry.npmjs.org/If pings are slow (>100ms) or curl hangs, your network connection is the issue.
For CI/CD environments (GitHub Actions, GitLab CI, etc.), add timeout configuration to your workflow YAML. Use the --no-audit flag to skip security audits which can add time: npm install --no-audit --prefer-offline. If using yarn or pnpm, they handle slow connections better with retry logic and parallel downloads, making them alternatives worth considering.
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