Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vite-proxy ECONNREFUSED with node v17+

Tags:

vue.js

vite

I am using Node v18.12.1 and vite v3.0.4. Below is my proxy code to connect to a Node.js REST API from the Vue.js vite dev server:

proxy: {
  "/api": {
    target: "http://localhost:3000",
    changeOrigin: true,
  }
}

After updating my node version from v16 I now get this error from vite-proxy:

[vite] http proxy error:
Error: connect ECONNREFUSED ::1:3000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) (x3)

I have heard that sine v17, Node favours ipv6 for localhost. How do I fix this?

like image 866
user14131782 Avatar asked Jul 12 '26 12:07

user14131782


1 Answers

You could run the service you are trying to connect to on ::1 or configure your proxy target to use the IPv4 address (http://127.0.0.1:3000).

like image 133
Quentin Avatar answered Jul 15 '26 07:07

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!