Home > Software design >  Vite-proxy ECONNREFUSED with node v17
Vite-proxy ECONNREFUSED with node v17

Time:11-19

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?

CodePudding user response:

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).

  • Related