npm-consider
                                
                                 npm-consider copied to clipboard
                                
                                    npm-consider copied to clipboard
                            
                            
                            
                        Getting error - reason: connect ETIMEDOUT
Symptom
When I run npm-consider install, it goes through tens of packages and then at one point it gives ETIMEOUT. Every time I retry, it stops at different points.
Suggested Fix
Either retry, or expand timeout?
How to reproduce
I am using vue-cli.
vue create npm-consider-test
<<< click enter and then wait for a minute >>>
cd npm-consider-test
npm-consider install
Outputs I get
PS C:\temp\npm-consider-test> npm-consider install
[email protected]
GET https://registry.npmjs.org/p-limit{ FetchError: request to https://registry.npmjs.org/@babel%2fpreset-stage-2 failed, reason: connect ETIMEDOUT 104.16.20.35:443
    at ClientRequest.<anonymous> (C:\Users\kennethc\AppData\Roaming\npm\node_modules\npm-consider\node_modules\node-fetch\index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'FetchError',
  message: 'request to https://registry.npmjs.org/@babel%2fpreset-stage-2 failed, reason: connect ETIMEDOUT 104.16.20.35:443',
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT' }
PS C:\temp\npm-consider-test> npm-consider install
[email protected]
GET https://registry.npmjs.org/run-queue{ FetchError: request to https://registry.npmjs.org/cssnano failed, reason: connect ETIMEDOUT 104.16.20.35:443
    at ClientRequest.<anonymous> (C:\Users\kennethc\AppData\Roaming\npm\node_modules\npm-consider\node_modules\node-fetch\index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'FetchError',
  message: 'request to https://registry.npmjs.org/cssnano failed, reason: connect ETIMEDOUT 104.16.20.35:443',
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT' }
PS C:\temp\npm-consider-test>
@kennethchoe any chance you can fork it and play with timeout here https://github.com/delfrrr/npm-consider/blob/master/lib/getPackageDetails.js#L85 and here https://github.com/delfrrr/npm-consider/blob/master/lib/getPackageDetails.js#L107
Timeout can be set in node-fetch https://github.com/bitinn/node-fetch
If it works, I will add the parameter for timeout, if not, I will implement retry then;
As non-hardcore-node developer, going through the code to test your suggestion out was very good exercise for me. Learned a lot of things.
Things you might want to know:
- 
I am using npm 5.6.0, which is up-to-date. I found some reports around ETIMEDOUT error suggesting you want to make sure you are using latest version of npm. 
- 
I am not using proxy. Still, I ran the following commands. 
npm config rm proxy
npm config rm https-proxy
- node-fetch's timeout option did not work. I learned that- node-fetchwill report the timeout error in different wording by looking at https://github.com/bitinn/node-fetch/blob/master/src/index.js/#L55-L67.
		if (options.timeout) {
			req.once('socket', function(socket) {
				reqTimeout = setTimeout(function() {
					req.abort();
					reject(new FetchError('network timeout at: ' + options.url, 'request-timeout'));
				}, options.timeout);
			});
		}
		req.on('error', function(err) {
			clearTimeout(reqTimeout);
			reject(new FetchError('request to ' + options.url + ' failed, reason: ' + err.message, 'system', err));
		});
- When it fails, it fails from a request made a while ago, not the last request. I made console.logon both occasions you pointed out. On one test, the output showed about 2000 requests to https://registry.npmjs.org before it reported ETIMEDOUT, and the one ETIMEDOUT error was reported at the end was actually for the 379th call.
I hope this helps.
I tested ut a bit more and sometimes I would get ETIMEDOUT as well. I see two solutions:
quick one: decrease number of parallel requests (parallel threads in a queue, now =20)
https://github.com/delfrrr/npm-consider/blob/eba62db7c346d6dfaeb7e1b8d550e631a8d59c76/lib/walkDependencies.js#L58
@kennethchoe can you test if this helps?
Then, this number can be configured via parameters
Implement retry (this package looks promising https://github.com/jonbern/fetch-retry#readme)
I tried with new Queue(1, Infinity);. It was much slower, of course, and still got the error eventually.
By the way, brilliant library it is - promise-queue.
I've started taking a look into fetch retry that @delfrrr mentioned above, will keep you posted.
In windows 10 -> Settings -> Internet and Networks ->Proxy
you'll find proxy, so set that proxy using this commands
npm config set proxy _your proxy_
npm config set https-proxy _your proxy_
It works for me