nuxt: Cannot start nuxt: Unable to obtain an available random port number!

Environment


  • Operating System: MacOS
  • Node Version: v16.14.0
  • Nuxt Version: Nuxt 3.3.2 with Nitro 2.3.2
  • Package Manager: yarn@1.22.10
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Create a nuxt project yarn yarn dev

Describe the bug

Nuxi 3.3.2
Nuxt 3.3.2 with Nitro 2.3.2

Local: http://localhost:3000/ Network: http://192.168.2.122:3000/

ERROR Cannot start nuxt: Unable to obtain an available random port number!

at getRandomPort (node_modules/get-port-please/dist/index.mjs:154:11)
at async findPort (node_modules/get-port-please/dist/index.mjs:238:24) at async getPort (node_modules/get-port-please/dist/index.mjs:137:21) at async listen (node_modules/listhen/dist/index.mjs:377:16) at async node_modules/@nuxt/content/dist/module.mjs:519:31 at async initNitro (node_modules/nuxt/dist/index.mjs:2080:3) at async initNuxt (node_modules/nuxt/dist/index.mjs:2503:3) at async load (node_modules/nuxi/dist/chunks/dev.mjs:6824:9) at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:6874:5) at async _main (node_modules/nuxi/dist/cli.mjs:49:20)

Additional context

No response

Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 20 (8 by maintainers)

Most upvoted comments

I was able to solve this issue by removing NUXT_HOST="http://localhost:8080" from .env files

The same issue.

  • Operating System: OpenSuse Tumbleweed
  • Node Version: 16, 18
  • Nuxt Version: Nuxt 3.3.3 with Nitro 2.3.2, Nuxt 3.1.2 with Nitro 2.1.1
  • Package Manager: latest npm
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Description: I think it’s a system problem. But the configuration has not changed, there have been no updates. Both old versions and a fresh installation from scratch suddenly stopped working. I have already tried disabling the firewall, extinguishing background processes, using different versions of npm and node.

$ lsof -PiTCP -sTCP:LISTEN
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java     5314 kapitansen   27u  IPv6  20474      0t0  TCP localhost:6942 (LISTEN)
java     5314 kapitansen   61u  IPv6  37413      0t0  TCP localhost:63342 (LISTEN)
spotify 22039 kapitansen   91u  IPv4 118334      0t0  TCP *:57621 (LISTEN)
spotify 22039 kapitansen   96u  IPv4 111054      0t0  TCP *:33031 (LISTEN)

PORT=3000 npm run dev and nuxt dev --port 3000 results to the same error.

Thanks for the reports. It seems the issue is commonly related to invalid or occupied HOST.

I think we can improve this upstream with fallback host support ~> https://github.com/unjs/get-port-please/issues/57

Also PR welcome to improve error with explicit host (https://github.com/unjs/get-port-please/issues/58)

The same issue.

* Operating System: OpenSuse Tumbleweed

* Node Version: 16, 18

* Nuxt Version: Nuxt 3.3.3 with Nitro 2.3.2, Nuxt 3.1.2 with Nitro 2.1.1

* Package Manager: latest npm

* Builder: vite

* User Config: -

* Runtime Modules: -

* Build Modules: -

Description: I think it’s a system problem. But the configuration has not changed, there have been no updates. Both old versions and a fresh installation from scratch suddenly stopped working. I have already tried disabling the firewall, extinguishing background processes, using different versions of npm and node.

$ lsof -PiTCP -sTCP:LISTEN
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java     5314 kapitansen   27u  IPv6  20474      0t0  TCP localhost:6942 (LISTEN)
java     5314 kapitansen   61u  IPv6  37413      0t0  TCP localhost:63342 (LISTEN)
spotify 22039 kapitansen   91u  IPv4 118334      0t0  TCP *:57621 (LISTEN)
spotify 22039 kapitansen   96u  IPv4 111054      0t0  TCP *:33031 (LISTEN)

PORT=3000 npm run dev and nuxt dev --port 3000 results to the same error.

I have same system. Solution for me in redefinition NUXT_HOST variable: NUXT_HOST="127.0.0.1" yarn dev or NUXT_HOST="" yarn dev

It seems like this is due to explicit overriding of the host rather than an issue in Nuxt itself.

However, I think we likely should update the error message in this case as it is a little confusing.