Bun runtime compatibility issue with whois npm library causing infinite execution

I’m having trouble with a whois lookup library when running it on Bun. I created a basic script called domain-lookup.js that works perfectly fine with Node.js but gets stuck in an endless loop when executed with Bun.

const whoisLookup = require('whois-json');

async function checkDomain() {
  try {
    const domainInfo = await whoisLookup('example.com');
    console.log('Domain details:', domainInfo);
  } catch (error) {
    console.error('Lookup failed:', error);
  }
}

checkDomain();

When I run this with node domain-lookup.js, it completes successfully and shows the domain information. However, when I execute it with bun run domain-lookup.js, the process never finishes and I have to manually terminate it. Has anyone encountered similar compatibility problems with whois libraries in Bun? Any suggestions for workarounds would be appreciated.

Yeah, this is a common Bun issue. The whois-json library doesn’t play nice with Bun’s TCP connections and event loop - it’s different enough from Node’s that you get these infinite loops. I usually add setTimeout(() => process.exit(1), 10000) before the whois call to see if it’s actually stuck or just really slow. Better yet, skip the socket connections entirely and use a fetch-based API like whoisjson.com. HTTP works way better with Bun right now.

Had this exact problem a few months ago when moving domain validation scripts to Bun. It’s how Bun handles Node.js APIs that whois libraries need - DNS resolution and socket stuff mainly. The whois-json package just doesn’t play nice with Bun’s networking. I switched to ‘node-whois’ instead, which works way better with Bun. You could also try wrapping your whois call with Promise.race() for a manual timeout as a quick fix. Bun’s networking stack isn’t quite there yet compared to Node.js, and whois lookups are one of those things that still act weird.

yeah, bun’s still buggy with some npm packages. try bun --bun when running your script - it forces bun’s runtime instead of node compatibility mode. if that doesn’t work, spawn a child process with node just for the whois part and keep everything else in bun. it’s hacky but works until they fix these networking issues.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.