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_DEV_SERVER_URL returning random port #164

Open
abarke opened this issue Sep 12, 2023 · 5 comments
Open

VITE_DEV_SERVER_URL returning random port #164

abarke opened this issue Sep 12, 2023 · 5 comments

Comments

@abarke
Copy link

abarke commented Sep 12, 2023

Since I upgraded my dependencies to the latest (see table), electron no longer starts on port 3000.

┌────────────────────────────┬─────────┬────────┐
│ Package                    │ Current │ Latest │
├────────────────────────────┼─────────┼────────┤
│ @aws-amplify/ui-vue        │ 3.1.23  │ 3.1.27 │
├────────────────────────────┼─────────┼────────┤
│ @types/uuid (dev)          │ 9.0.2   │ 9.0.3  │
├────────────────────────────┼─────────┼────────┤
│ electron-builder (dev)     │ 24.6.3  │ 24.6.4 │
├────────────────────────────┼─────────┼────────┤
│ @vueuse/rxjs               │ 10.3.0  │ 10.4.1 │
├────────────────────────────┼─────────┼────────┤
│ nuxt (dev)                 │ 3.6.5   │ 3.7.1  │
├────────────────────────────┼─────────┼────────┤
│ electron (dev)             │ 25.4.0  │ 26.2.0 │
├────────────────────────────┼─────────┼────────┤
│ vite-plugin-electron (dev) │ 0.12.0  │ 0.14.1 │
└────────────────────────────┴─────────┴────────┘

Vite seems to start on 3000, however when I dump the VITE_DEV_SERVER_URL variable it says http://localhost:51316 🤔

image

Any ideas?

@abarke
Copy link
Author

abarke commented Sep 12, 2023

Workaround in main.ts

  if (process.env.VITE_DEV_SERVER_URL) {
    mainWindow.loadURL("http://localhost:3000"); // dev
  } else {
    mainWindow.loadFile("dist/index.html"); // production
  }

@HMaker
Copy link

HMaker commented Nov 12, 2023

This bug makes cookies and localstorage be lost at every electron restart. Since the port randomly changes the server origin changes, thus Electron (aka chromium) won't load the persisted data.

@caoxiemeihao
Copy link
Member

Who can provide a 100% reproduction repo?

@abarke
Copy link
Author

abarke commented Nov 13, 2023

This bug makes cookies and localstorage be lost at every electron restart. Since the port randomly changes the server origin changes, thus Electron (aka chromium) won't load the persisted data.

Indeed this was the same issue for me. The current workaround for me is the following:

  if (process.env.VITE_DEV_SERVER_URL) {
    mainWindow.loadURL("http://localhost:3000"); // dev
  } else {
    mainWindow.loadFile("dist/index.html"); // production
  }

@lvbaiying
Copy link

@caoxiemeihao You can try the quick start demo and print VITE_DEV_SERVER_URL after running it. It will indeed be generated randomly every time and needs to be specified manually like above. My current temporary solution is to get 0.0.0.0 from process.env.NUXT_DEV and replace it. into localhost and put it in loadURL。

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

4 participants