nuxt: Unable to obtain an available random port number!

Environment

Nuxi 3.2.0

RootDir: /home/visitante/Downloads/naturale Nuxt project info:


  • Operating System: Linux
  • Node Version: v18.14.0
  • Nuxt Version: 3.2.0
  • Nitro Version: 2.2.1
  • Package Manager: pnpm@7.27.0
  • Builder: vite
  • User Config: css, app
  • Runtime Modules: -
  • Build Modules: -

Reproduction

  • Create a nuxt project
  • pnpm i
  • pnpm dev

Describe the bug

So, I’m started studding Nuxt3 some time ago and created a repository for this. Everything went well until today, when I format my computer.

I clone my repo again, but when I try to run the dev command, I got this error:

Nuxi 3.2.0                                                                                                           14:07:22
Nuxt 3.2.0 with Nitro 2.2.1                                                                                          14:07:22

 ERROR  Unable to obtain an available random port number!                                                            14:07:22
                                                                                                                     14:07:22
  at getRandomPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:165:11)
  at async findPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:236:24)
  at async getPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:148:21)
  at async listen (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:704:16)
  at async Object.invoke (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/dev.mjs:6758:22)
  at async _main (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/cli.mjs:51:20)

 ELIFECYCLE  Command failed with exit code 1.

I did nothing but install git, node lts (using nvm), pnpm and cloning the repo.

I tried to run the command with a different Node, npm and pnpm versions, but didn’t help it.

It also happens if I create a new project with pnpm dlx nuxi init <project-name>.

Additional context

image

Logs

Nuxi 3.2.0                                                                                                           14:07:22
Nuxt 3.2.0 with Nitro 2.2.1                                                                                          14:07:22

 ERROR  Unable to obtain an available random port number!                                                            14:07:22
                                                                                                                     14:07:22
  at getRandomPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:165:11)
  at async findPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:236:24)
  at async getPort (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:148:21)
  at async listen (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/index.mjs:704:16)
  at async Object.invoke (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/chunks/dev.mjs:6758:22)
  at async _main (node_modules/.pnpm/nuxi@3.2.0/node_modules/nuxi/dist/cli.mjs:51:20)

 ELIFECYCLE  Command failed with exit code 1.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (15 by maintainers)

Most upvoted comments

It appears that if a port is set explicitly in the config, and that port is already in use, random port selection does not occur.

Thank you both 😃

Would be nice to add a better error message when that port is taken.

We recently added support for devServer. When host is specified, get-port tried to listhen to the port/host combination

Are you setting a HOST environment variable by any chance somewhere @L422Y? Feel free to DM me in discord this might be an env specific issue we might investigate more to resolve pi0#6582