4
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?

More than 1 year has passed since last update.

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

Posted at

事の始まり

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]にアクセスしているせい
というよりよく見ると普通に書いてある

対処法

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

vite.config.ts
import dns from "dns";
dns.setDefaultResultOrder("ipv4first");
4
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
4
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?