iTranslated by AI
Why fetch stopped working after updating Node.js
Introduction
I welcome corrections or additions to this article through comments or GitHub pull requests.
Conclusion
The issue was resolved by changing localhost to 127.0.0.1.
127.0.0.1 is a special address pointing to the host itself, which is the same as the value of localhost resolved via ipv4.
Background
I had been using Node v16.16.0 until now, but since it was getting quite old, I decided to take the plunge and update to the latest v19.3.0.
However, I found myself unable to fetch after the update.
error - Error [FetchError]: request to http://localhost:3001/ failed, reason: connect ECONNREFUSED ::1:3001
Cause
The cause was that with the update to Node.js, IPv6 began to be used by default.
localhost was being resolved to the IPv6 address ::1, which caused an error within the library.
Solution
It was resolved by changing localhost to 127.0.0.1.
127.0.0.1 is a special address pointing to the host itself, and is the same as the value of localhost resolved via IPv4.
Discussion