-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
App keeps refreshing with log: Server connection lost polling for restart
#4259
Comments
Got the same problem on 2.3.7 as well. It can be reproduced if you have hmr.host set to localhost in your vite.config.js
Solution: Remove the whole hmr key in your vite.config.js it should be something like this:
@to vitejs devs: maybe on iOS, you should detect we've set localhost for hmr.host and prevent the flicking / constant page refresh / or ignore the hmr.host: 'localhost'. The good news is that I got 15000 pageviews on Google Analytics in a few seconds, it make me feel my app is super successful ;-) |
@dmx374 I haven't set I'm wondering if the certificate has something to do with it. I used the following command to crete it: |
I can reproduce this locally in vite
|
Are y'all running your projects in docker containers? When I run the server in docker I experience this issue and hot reload is also broken. When I run the server locally, though, instead of in a container, I don't get this error and hot reload works as expected. |
@mrweiner I personally don't, I run it locally. |
@mrweiner My minimal reproduction involved no Docker containers, but I first experienced it in conjunction with Docker, which motivated me to find a minimal reproduction. |
I'm having the same issue (vite 2.4.4). I run the vite server in a docker container, and use a reverse proxy to route the HTTPS traffic to this container. I already set |
Also started having this problem, but only in Chrome, not in Firefox. Changing the various |
Hi The websocket connection keeps failing. I am using current Edge but also tested in Chrome. NB: all is well with same setup under HTTP. |
Would you test your projects using vite@2.5.0-beta.1 ? |
@patak-js I have the same problem described above and now I also get this error:
I'm not sure what it could be. |
just tried it, still no luck. |
UPDATE: tried |
UPDATE: I was able to resolve the issue by setting the |
I was not able to resolve it with any of the suggestions. The only temporary fix was |
@pzmosquito can you please share your full config? I've managed to get this to not reload. The WS never connects, but at least it doesn't reload and I can use non-built/non-minified JS/TS(x) files. server: {
// host: '0.0.0.0',
// https: true,
hmr: {
host: 'ad345ds2.ngrok.io',
// port: 443,
// protocol: 'wss',
},
}, Uncommenting PS I'm using ngrok tunnel. |
import path from "path";
import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
export default defineConfig({
mode: "development",
resolve: {
alias: {
_: path.resolve(__dirname, "src"),
},
},
plugins: [
reactRefresh(),
],
clearScreen: false,
server: {
host: "0.0.0.0",
port: 3000,
strictPort: true,
hmr: {
port: 443,
},
},
}); |
In CodeSandbox traffic is routed to port 3000 from an SSL proxy on port 443. Vite will by default look for port 3000, instead of port 443. The only configuration needed to make it work was changing the HMR port.
Working codesandbox: https://codesandbox.io/s/vite-hmr-fix-4259-h6c2l?file=/vite.config.ts:180-227 |
I tried all of the above solutions and finally found a solution that works for me. 🎉 Here's what works for me:
So in my case:
|
@vfonic what is the significance of port 3036 -- how did you determine or specify that it's for Vite's HMR traffic? What did you do with the tunnel URL produced by localtunnel? Maybe sharing your full config would help. Trying to better understand the setup for using Vite behind Ngrok. |
@mattrossman that's the port that I've set the vite to run on in {
"all": {
"sourceCodeDir": "app/javascript",
"watchAdditionalPaths": []
},
"development": {
"autoBuild": true,
"publicOutputDir": "vite-dev",
"port": 3036
},
"test": {
"autoBuild": true,
"publicOutputDir": "vite-test"
}
} This is the default setup that |
I experienced this same issue when building with docker. In the container my app runs on port
Clues above in posts regarding people using reverse proxies made me realize that I needed to add this to my
This immediately fixed my issue. |
need to set strictPort=true, thanks a lot |
There are two issues that talk about similar/the same issue. This one and Vite HMR is unusable behind reverse proxies with random port numbers for client. I posted my config there, so here it is here as well:
// ...
export default defineConfig({
// ...
server: {
hmr: {
host: `some-ngrok-subdomain.loca.lt`,
port: 443,
},
},
// ...
"devDependencies": {
"localtunnel": "2.0.1",
"ngrok": "^4.2.2"
} And then I start everything: ./node_modules/.bin/lt --subdomain=some-ngrok-subdomain --port=3036
./node_modules/.bin/ngrok http -subdomain=some-ngrok-subdomain |
* chore: exec `yarn create vite template --template vue` * chore: setup eslint * fix: CodeSandboxで `yarn dev` すると一定間隔で更新される See: vitejs/vite#4259 (comment) * chore: setup codesandbox config * chore: specify node version * fix: wrong config name * fix: not working with specifying node 16 mainly sandbox.config.json issue, maybe? * chore: specify node version (take 2) * chore: remove eslint Because - codesandbox can't load user eslint config - stackblitz can load volar as vscode ext * docs: hmrのポート番号をデフォルトから変更している背景 * chore: specify package manager version * chore: use npm instead of yarn because stackblitz use npm by default and I don't know how to change this * chore: rename template as vite-template, etc. for prepare nuxt-template creation & practice* creation * chore: exec `npx nuxi init nuxt-template` * chore: drop CodeSandbox support * chore: apply vscode settings to entire dirs * chore: apply node version to entire dirs * chore: fill package.json * docs: 使い方 * chore: switch from npm to yarn again - stackblitz doesn't auto exec when import the monorepo - yarn workspace function is more confortable than npm * chore: re-setup CodeSandbox config * docs: CodeSandboxでの実行手順
Happy to report for vite.config.ts:
Edit: happy to report this works without specifying the host. |
None of the methods mentioned here worked when using |
I think I got this working with NGINX (vite 2.7.1): in your nginx config add an explicit mapping for the socket connection:
then in the vite.config.js do something similar for the HMR section:
I also had to add this to the docker file running Vite (which I don't like, but seemed to work):
|
Thanks for the quick reply but it doesn't seem to work |
Maybe related #6068 |
Hi, I'm developing in localhost with Docker, and for me, the valid config is:
Or try to use ssl with mkcert (https://github.com/FiloSottile/mkcert#installation) I hope it helps. |
I'm quite sure this is not related to Docker nor ngrok. My app is running locally and I had the same issue- if I enable a CORS extension my app was constantly refreshing. If you experience the same have a look into your web developer tools console logs and enable "Preserve logs" - you may see error messages like WebSocket connection to 'ws://localhost:xxxx/' failed. What was working for me is to not open my app via "http://localhost:xxx..." but "http://127.0.0.1:xxx...." instead - no config change necessary. If you don't like to use "http://127.0.0.1..." in your URL for some reason it may also work if you change your hmr config to use 127.0.0.1 as a specific host like this:
|
Same issue with Electron v17. Super annoying to debug as inside of Electron you cannot read the logs in the console because it constantly reloads. In the electron main process you only get something like:
Took a while for me to connect this issue with the vite websocket. After commeting out the reload in the Vite client at the socket close listener, I could at least see the logs in the Electron renderer. Interestingly, changing the protocol in Using a valid certificate for vite, with the help of The biggest issue is debugging this as initially there seems to be no indication this issue is connected to Vite without being able to see the console. I guess the root cause might be Electron, but maybe we can also do something to prevent endless reloading on Vite's site? |
Because I wanted to achieve a local-to-git-to-codesandbox flow, here is how I got Vite working for both local development and CodeSandbox without the refresh issue.
Working sandbox: Git repo: |
I am experiencing this issue with UPDATE: Here is my
|
@aflansburg #4259 (comment) Likewise anyone else that works with a Docker environment and got the websockets working with a Node app through Nginx, it would be great to be able to have a look at how you have set up things to work, thank you. |
Sure thing, this is my setup / config, hope this helps. docker-compose.yaml
Here is my vite.config.ts:
And my Nginx config (these may not be the actual port numbers used):
|
Hi sorry for the delay. My project is public monorepo and can be seen here. I haven't been able to work on it as of late, but essentially components are:
|
setting the clientPort if you using docker fix my issue |
If anyone is interested, I am using Devilbox for local "remote" development and have thus everything in containers and the host is left clean. Here is an example setup with SvelteKit and NGINX proxy. https://github.com/robots4life/devilskit |
Closing as #8650 covers most reported cases here. Please try 3.0.0-beta.1. |
Describe the bug
In certain situation the app keeps refreshing indefinitely giving this log in console:
server connection lost polling for restart
.I'm using vite 2.4.2 with https, react and typescript.
Reproduction
I noticed this happen in this 2 situations:
vite
with the--host
flag and accessing it with my phone (Safari on iOS 14) via the shared url:https://192.168.1.xxx:3000
. Removing the https option "solves" the problem on iOS.System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: