Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite HMR Websocket Connection failed #413

Open
crtl opened this issue Aug 29, 2024 · 8 comments
Open

Vite HMR Websocket Connection failed #413

crtl opened this issue Aug 29, 2024 · 8 comments

Comments

@crtl
Copy link

crtl commented Aug 29, 2024

When creating a new project and also on my existing project I get the following error when running npm run dev in the browser:

client:535 WebSocket connection to 'ws://127.0.0.1:24678/' failed: 
setupWebSocket @ client:535
(anonym) @ client:530
client:556 [vite] server connection lost. Polling for restart...

To fix this issue I have to set the host to localhost in vite hmr options:

await app.register(remixFastify, {
    viteOptions: {
        server: {
            hmr: {
                protocol: "ws",
                host: "localhost",
            }
        }
    }
});
@swalker326
Copy link
Contributor

Do you have a repo link? When I run npx create-remix@latest --template mcansh/remix-fastify/examples/vite and npm run dev the app is running on localhost:3000

image

@crtl
Copy link
Author

crtl commented Sep 3, 2024

@swalker326 The error happens client side.

@swalker326
Copy link
Contributor

image

@crtl
Copy link
Author

crtl commented Sep 3, 2024

ive tried it again it cant connect:

(base) crtl@DESKTOP:~/projects/crtl$ npx create-remix@latest --template mcansh/remix-fastify/examples/vite

 remix   v2.11.2 💿 Let's build a better website...

   dir   Where should we create your new project?
         test-remix-fastify

      ◼  Template: Using mcansh/remix-fastify/examples/vite...
      ✔  Template copied

   git   Initialize a new git repository?
         No

  deps   Install dependencies with npm?
         Yes

      ✔  Dependencies installed

  done   That's it!

         Enter your project directory using cd ./test-remix-fastify
         Check out README.md for development and deploy instructions.

         Join the community at https://rmx.as/discord

(base) crtl@DESKTOP:~/projects/crtl$ cd test-remix-fastify/
(base) crtl@DESKTOP:~/projects/crtl/test-remix-fastify$ npm run dev

> dev
> cross-env NODE_ENV=development tsx --watch-path ./server/index.ts ./server/index.ts

✅ app ready: http://127.0.0.1:3000

Console output is:
image

Maybe it is relevant that i am running it from WSL2.

node -v
v22.7.0

Ive also tried running in inkognito mode to make sure no browser extensions are interfering but the result is the same.

@swalker326
Copy link
Contributor

Interesting, do you see the same error when you run npx create-remix@latest and run the app?

@crtl
Copy link
Author

crtl commented Sep 3, 2024

No. The default remix template works fine.

@mcansh
Copy link
Owner

mcansh commented Sep 4, 2024

i haven't experienced this either and we're not doing anything different than the official templates do in the vite config

@crtl
Copy link
Author

crtl commented Sep 5, 2024

Its not a huge problem. The workaround ive posted works and I just wanted to document it here in case someone else has the same problem. Ive you need more info about my environment tell me. Otherwise we can close this too.

Heres my current solution. It seems only the host is relevant.

// vite.config.ts
import {vitePlugin as remix} from "@remix-run/dev";
import {defineConfig} from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
    envDir: "./",
    server: {
        hmr: {
            host: "localhost"
        }
    },
    plugins: [
        remix({
            future: {
                v3_fetcherPersist: true,
                v3_relativeSplatPath: true,
                v3_throwAbortReason: true,
            },
        }),
        tsconfigPaths(),
    ],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@swalker326 @mcansh @crtl and others