79671543

Date: 2025-06-19 05:05:37
Score: 0.5
Natty:
Report link

For anyone who lands here, a quick note:
I struggled with this issue too, and the fix turned out to be very simple:

Upgrade your Node.js version.
Starting in Node.js v17, localhost is resolved over IPv6 by default.
which causes this problem in all early v17–v23 releases.

In the latest Node.js releases, they’ve added logic to fall back to IPv4 if an IPv6 request fails. Installing the newest Node.js version resolves the issue.

I verified it on these versions:

17.2: issue occurred → upgraded to 17.9, issue resolved
18.11: issue occurred → upgraded to 18.20, issue resolved
23.12: issue occurred → upgraded to 23.16, issue resolved

If you can’t install every Node.js version, you can also work around it by:

1. Using the IPv4 address (127.0.0.1) instead of 'localhost'.

2. Adding this flag to your npm script:

--dns-result-order=ipv4first

2.1 For example, in my Next.js project’s package.json:

{
"scripts": {
"dev": "cross-env NODE_OPTIONS=\"--dns-result-order=ipv4first\" next dev --port 8000",
"start": "next start --port 8000"
},
"dependencies": {
"cross-env": "^7.0.3",

}
}

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: sj a