Strange Node.js NPM connection issues on Ubuntu VM with VirtualBox

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!

Had the same issue with corporate networks behind NAT. VirtualBox NAT doesn’t play nice with npm’s connection pooling and keep-alive connections. Fixed it by changing the host-only adapter MTU from 1500 to 1400. Cloudflare’s infrastructure fragments packets weirdly and causes those timeouts. Test it with ping -M do -s 1472 registry.npmjs.org in your VM - if large packets drop, lowering MTU will fix it without switching to bridge mode.

Sounds like VirtualBox’s NAT is dropping packets to Cloudflare. Try adding host_resolver=1 to your VM’s NAT settings - forces DNS through the host instead of the VM, which often fixes Cloudflare routing problems. Also try dns_proxy=1 since npm uses multiple CDN endpoints.

Classic VirtualBox NAT timeout issue. That 104.16.3.35 IP is Cloudflare - npm’s registry runs on their infrastructure and it’s pickier about NAT timeouts than regular sites. I hit this same problem last year. VirtualBox’s default NAT has short timeout values that clash with npm’s registry connections. The registry needs longer connections when pulling package metadata, especially for big packages. Bump up your NAT timeout values in VM settings - check Network > Advanced > Port Forwarding for custom timeout configs. Or switch to NAT Network instead of regular NAT since it handles timeouts differently. Also worth checking if your host firewall has rules blocking NAT translation for certain IP ranges. Bridge mode works because it skips VirtualBox’s NAT layer completely.