How to fix npm ERR! code E408 npm ERR! 408 Request Timeout in npm
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.
Quick fix
Fixes npm ERR! code E408 npm ERR! 408 Request Timeout
npm config set fetch-timeout 300000
npm config set fetch-retry-maxtimeout 120000
npm config set fetch-retry-mintimeout 20000- Increase npm timeout configuration
- Clear npm cache and node_modules
- Switch to a faster npm registry mirror
- Configure proxy settings if behind corporate network
npm config set fetch-timeout 300000npm config set fetch-retry-maxtimeout 120000npm config set fetch-retry-mintimeout 20000npm ERR! code E408npm ERR! 408 Request Timeout
What this error means
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.
Typical symptoms
- npm install stops mid-process with 'E408 Request Timeout' message
- Installation hangs for 30+ seconds before failing
- Specific packages consistently fail to download while others succeed
- npm works fine on mobile hotspot but fails on office Wi-Fi
- CI/CD pipelines timeout during npm install step
Common causes
- Slow or unstable internet connection not meeting npm's speed requirements
- npm registry server experiencing high load or temporary slowness
- Firewall or proxy intercepting requests and delaying responses
- Default timeout value (30 seconds) too short for your network conditions
- VPN or corporate network proxy adding latency to registry requests
How to fix "npm ERR! code E408 npm ERR! 408 Request Timeout"
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.
Advanced notes
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.
Frequently asked questions
- What does "npm ERR! code E408 npm ERR! 408 Request Timeout" mean?
- 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.
- How do I fix "npm ERR! code E408 npm ERR! 408 Request Timeout"?
- 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.
- What causes "npm ERR! code E408 npm ERR! 408 Request Timeout"?
- Slow or unstable internet connection not meeting npm's speed requirements npm registry server experiencing high load or temporary slowness Firewall or proxy intercepting requests and delaying responses
- Is the "npm ERR! code E408 npm ERR! 408 Request 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
- ๐MDN: HTTP 408 status(Official Docs)
- ๐ฌSO: npm timeout error(Stack Overflow)
- ๐