[BUG] Getting constant `FetchError...reason: Socket timeout` when installing packages
Problem
Current Behavior: When trying to install packages, without a previous cache, we get constant timeouts when trying to fetch packages, both locally and in a CI environment. The package that fails is always different, so there isn't a specific package causing the issue. Stack trace: [code block] Tried using the fetch-retries, fetch-retry-mintimeout, and fetch-retry-maxtimeout options, but didn't seem to have any effect. Expected Behavior: Install packages without timing out. Steps To Reproduce: Using a project with workspaces (~6425 packages) No cache available Run `npm ci` Environment: OS: Mac OS 11.2.3 or Windows 10 Node: 14.15.4 npm: 7.9.0
Error Output
Error: request to https://.../npm/registry/typescript/-/typescript-4.1.3.tgz failed, reason: Socket timeout
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Increase Socket Timeout for npm Install
The constant 'Socket timeout' errors during package installation are likely due to the default timeout settings in npm being too low for the current network conditions or the size of the workspace. When there are many packages and no cache, the requests may take longer than the default timeout, leading to these errors.
Awaiting Verification
Be the first to verify this fix
- 1
Increase npm Timeout Settings
Modify the npm configuration to increase the socket timeout settings. This will allow more time for requests to complete before timing out.
bashnpm config set fetch-retries 5 && npm config set fetch-retry-mintimeout 20000 && npm config set fetch-retry-maxtimeout 120000 - 2
Clear npm Cache
Clear the npm cache to ensure that no corrupted or outdated files are causing issues. This can help in reducing the chances of timeouts.
bashnpm cache clean --force - 3
Use a Different Registry
If the issue persists, try switching to a different npm registry or mirror that may have better response times. This can be done by setting the registry URL in npm.
bashnpm config set registry https://registry.npmjs.org/ - 4
Check Network Connection
Ensure that your network connection is stable and not causing interruptions. You may want to try connecting to a different network or using a VPN.
- 5
Run npm ci Again
After applying the above changes, attempt to run 'npm ci' again to see if the socket timeout issue is resolved.
bashnpm ci
Validation
Confirm that the 'Socket timeout' errors no longer occur during package installation by running 'npm ci' and checking for successful completion without timeouts.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep