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

Add ability to configure HMR port #27325

Closed
3 of 4 tasks
samupl opened this issue May 23, 2024 · 0 comments · Fixed by #27326
Closed
3 of 4 tasks

Add ability to configure HMR port #27325

samupl opened this issue May 23, 2024 · 0 comments · Fixed by #27326

Comments

@samupl
Copy link
Contributor

samupl commented May 23, 2024

Describe the feature

Currently, according to

const hmrPortDefault = 24678 // Vite's default HMR port
const hmrPort = await getPort({
port: hmrPortDefault,
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
})
the HMR port is static + if unable to bind to it, it is randomized until it fails:

    const hmrPortDefault = 24678 // Vite's default HMR port
    const hmrPort = await getPort({
      port: hmrPortDefault,
      ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i),
    })

In some environments (e.g. behind firewalls, or with limited permissions to bind to ports) it might be desirable to change the port used.

Case in point - an environment that only allows an user to bind to ports from a specified range (2000 - 3000). Running yarn dev on a fresh new nuxt project:

$ yarn dev
yarn run v1.22.22
$ nuxt dev
Nuxt 3.11.2 with Nitro 2.9.6      

...
 ERROR  [uncaughtException] listen EPERM: operation not permitted 127.0.0.1:45541                                                                                                                                                           14:51:58

  at Server.setupListenHandle [as _listen2] (node:net:1880:21)
  at listenInCluster (node:net:1945:12)
  at doListen (node:net:2109:7)
  at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Running yarn dev --no-fork seems to reveal the real issue:

$ yarn dev --no-fork
yarn run v1.22.22
$ nuxt dev --no-fork
Nuxt 3.11.2 with Nitro 2.9.6        

....

 ERROR  Cannot start nuxt:  Unable to find a random port on any host                                                                                                                                                                        14:53:32

  at getRandomPort (node_modules/get-port-please/dist/index.mjs:335:11)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async getPort (node_modules/get-port-please/dist/index.mjs:313:21)
  at async buildClient (node_modules/@nuxt/vite-builder/dist/shared/vite-builder.Cz3sykDo.mjs:537:21)
  at async bundle (node_modules/@nuxt/vite-builder/dist/shared/vite-builder.Cz3sykDo.mjs:1586:3)
  at async bundle (node_modules/nuxt/dist/index.mjs:5125:5)
  at async Promise.all (index 1)
  at async build (node_modules/nuxt/dist/index.mjs:5000:5)
  at async Promise.all (index 1)
  at async NuxtDevServer._load (node_modules/nuxi/dist/chunks/dev2.mjs:6924:5)
  at async NuxtDevServer.load (node_modules/nuxi/dist/chunks/dev2.mjs:6811:7)
  at async NuxtDevServer.init (node_modules/nuxi/dist/chunks/dev2.mjs:6806:5)
  at async Object.run (node_modules/nuxi/dist/chunks/dev.mjs:195:7)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1648:16)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1639:11)
  at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1777:7)

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

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

Successfully merging a pull request may close this issue.

1 participant