Having weird network problems with NPM on my setup
I’m running into some really frustrating connection issues and could use some help figuring this out.
My environment: Kubuntu 24 host, VirtualBox 7, using nvm 0.40.1 with Node 22.14.0 and npm 10.9.2
The problem: Getting ETIMEDOUT errors when trying to install npm packages. I’ve tried everything I could find online - different Node versions, clearing cache, changing DNS servers, even set up a local DNS server. Nothing worked!
I made a test script using the https module to check connectivity to the npm registry and got tons of errors. IPv4 gives me ETIMEDOUT and IPv6 throws ENETUNREACH when accessing package info.
The weird part is that other sites work fine - I can reach Google, Microsoft, Docker hub without any issues.
What I tested:
- VirtualBox with Debian 12 using NAT = Same errors
- VirtualBox with Debian 12 using Bridge mode = Everything works!
- Docker containers with various Node versions = All working perfectly
Test script I used:
const http = require('https');
http.get('https://registry.npmjs.org/lodash', (response) => {
console.log('Status:', response.statusCode);
console.log('Response headers:', response.headers);
let chunks = [];
response.on('data', (chunk) => {
chunks.push(chunk);
});
response.on('end', () => {
const output = chunks.join("");
console.log(output);
});
}).on('error', (err) => {
console.error(err);
});
Error output:
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)
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.16.3.35',
port: 443
}
]
}
Anyone have ideas why NPM registry specifically fails with NAT networking but works fine with bridge mode or in Docker? This is driving me crazy!