vite icon indicating copy to clipboard operation
vite copied to clipboard

Dev server not working on GitHub Codespaces

Open Koenkk opened this issue 1 year ago • 8 comments

I'm trying to run the Vite Dev server with the vite-remote example on GitHub Codespaces but it doesn't work. This issue is not limited to GitHub Codespaces, it fails whenever the dev server is not reachable on localhost (which is also the case when you run the dev server behind a reverse proxy, Coder or GitLab workspaces).

Issue

The issue is that it tries to load remoteEntry-[hash].js from localhost:5173 which is both the wrong hostname and port. For the example below, it should have used https://upgraded-journey-pg6jpg4vp539wr-5176.app.github.dev:443/testbase/remoteEntry-[hash].js.

image

Steps to reproduce

cd vite-remote
pnpm i --frozen-lockfile
pnpm run dev
  • A new tab should open in the browser which shows the issue

Analysis

I did some analysis on why this occurs. I believe the code below should allow specifying a different host and port (hacking this manually in the node_modules folder fixes the issue)

https://github.com/module-federation/vite/blob/aaa23f59a8fbc7fc054010ba453bdc20186f9ac0/src/plugins/pluginProxyRemoteEntry.ts#L60

Alternatively, I tried changing the Vite config as follows but then pnpm run dev doesn't work:

  server: {
    open: true,
    port: 5176,
+   host: 'upgraded-journey-pg6jpg4vp539wr-5176.app.github.dev',
    origin: 'http://localhost:5176',
  },
@Koenkk ➜ /workspaces/vite-plugin-federation-issue/vite-remote (main) $ pnpm run dev

> [email protected] dev /workspaces/vite-plugin-federation-issue/vite-remote
> vite

Forced re-optimization of dependencies
error when starting dev server:
Error: listen EADDRNOTAVAIL: address not available 20.103.221.187:5176

Koenkk avatar Dec 09 '24 10:12 Koenkk

Thanks @Koenkk for the commitment you put into this issue. Would you like to find a solution to make it works?

gioboa avatar Dec 09 '24 15:12 gioboa

@gioboa yes but I would need some guidance on how a proper fix should look like, does adding a new config option for this make sense?

Koenkk avatar Dec 10 '24 19:12 Koenkk

The first step is to figure out how to solve this problem and make it works, you can hack the library and modify it directly. Then we can figure out what we need to change in the library. Does that make sense to you?

gioboa avatar Dec 10 '24 20:12 gioboa

I already hacked it locally and then it works, made the following change (pseudo, because I modified the transpiled JS version):

host = 'upgraded-journey-pg6jpg4vp539wr-5176.app.github.dev'
port = 443
const {init} = await import("//${host}:${port}${viteConfig.base + options.filename}")

Koenkk avatar Dec 11 '24 20:12 Koenkk

@Koenkk That's great :clap: we can config host and port with viteConfig.server.host viteConfig.server.port Here is the code

gioboa avatar Dec 11 '24 20:12 gioboa

@gioboa that's what I already tried, but then Vite refuses to start, see the OP.

Alternatively, I tried changing the Vite config as follows but then pnpm run dev doesn't work:

I think this should be a separate optional option, and in case it's not specified use the Vite config.

Koenkk avatar Dec 12 '24 08:12 Koenkk

@Koenkk Let's try the separate option, make it work. then we can decide whether we need it or not. WDYT?

gioboa avatar Dec 20 '24 15:12 gioboa

@gioboa sounds good! Will give it a shot.

Koenkk avatar Dec 21 '24 20:12 Koenkk

As there's been no activity for 30 days, this issue has been flagged as stale. If you'd like it to remain open, please add a comment within the next 7 days. Thank you.

github-actions[bot] avatar Oct 29 '25 14:10 github-actions[bot]