I was getting ETIMEDOUT when installing packages with nvm 0.40.1, node 22.14.0& npm v10.9.2. Tried multiple fixes that's across the internet and nothing worked! (downgrade, upgrade, cleanup, switching dns, installing Pihole on a machine & using that for DNS).
I wrote a simple script with require('https') to read https://registry.npmjs.org and got a boatload of Aggregate Error with ETIMEDOUT for IP4& ENETUNREACH for IP6 when trying to get any package page eg: https://registry.npmjs.org/data-fns
At same time, fetching google.com, microsoft.com, docker.com & many more works!
So I decided to try these
- VirtualBox 7 + Debian 12 + NAT networking = Not Working, same errors for npm & script
- VirtualBox 7 + Debian 12 + BRIDGE networking = WORKING both script & npm install
- Docker - tried multiple LTS v18/20/22 = All WORKING both script & npm install
NPM Config for Kubuntu & Debian VM(on docker is default ie similar with different path)
$ npm config ls; node bin location = /home/USER/.nvm/versions/node/v22.14.0/bin/node; node version = v22.14.0; npm local prefix = /home/USER/works/nodetest; npm version = 10.9.2; cwd = /home/USER/works/nodetest; HOME = /home/USER; Run `npm config ls -l` to show all defaultsscript
const https = require('https');https.get('https://registry.npmjs.org/data-fns', (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers); const data = []; res.on('data', (d) => { data.push(d); }); res.on('end', ()=>{ const result = data.join("") console.log(result); });}).on('error', (e) => { console.error(e);});HTTPS webpage Fetch Script error for https://registry.npmjs.org
truncated but this repeats for multiple addresses
AggregateError [ETIMEDOUT]: at internalConnectMultiple (node:net:1139:18) at internalConnectMultiple (node:net:1215:5) at Timeout.internalConnectMultipleTimeout (node:net:1739:5) at listOnTimeout (node:internal/timers:596:11) at process.processTimers (node:internal/timers:529:7) { code: 'ETIMEDOUT', [errors]: [ Error: connect ETIMEDOUT 104.16.3.35:443 at createConnectionError (node:net:1675:14) at Timeout.internalConnectMultipleTimeout (node:net:1734:38) at listOnTimeout (node:internal/timers:596:11) at process.processTimers (node:internal/timers:529:7) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '104.16.3.35', port: 443 }, Error: connect ENETUNREACH 2606:4700::6810:1f22:443 - Local (:::0) at internalConnectMultiple (node:net:1211:16) at Timeout.internalConnectMultipleTimeout (node:net:1739:5) at listOnTimeout (node:internal/timers:596:11) at process.processTimers (node:internal/timers:529:7) { errno: -101, code: 'ENETUNREACH', syscall: 'connect', address: '2606:4700::6810:1f22', port: 443 }, ...