LoginSignup
3
2

【備忘録】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");
3
2
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
3
2