5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】Viteでlocalhostへの接続がうまくいかないときの対処法

Last updated at Posted at 2023-08-24

事の始まり

Viteの公式サイトをみて、下のようにProxyの設定をしていたのだが、Error: connect ECONNREFUSED ::1:48383となっていて接続できない

export default defineConfig({
  server: {
    open: true,
    proxy: {
      "/api": {
        target: "http://localhost:48383/",
        changeOrigin: true,
      },
    },
  },
  plugins: [react()],
});

結論

NodeがデフォルトでIPv6を使うようになったので[::1]にアクセスしているせい
というよりよく見ると普通に::1:48383と書いてある

対処法

このコードを入れてIPv4でアクセスするようにする

vite.config.ts
import dns from "dns";
dns.setDefaultResultOrder("ipv4first");
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?