evgeni fotia
evgeni fotia

Reputation: 4810

can't get Next.js to work with custom hostname

when I run npm run dev -- -H 192.168.1.100 I got this error

{ Error: listen EADDRNOTAVAIL: address not available 192.168.1.100:3000
    at Server.setupListenHandle [as _listen2] (net.js:1273:19)
    at listenInCluster (net.js:1338:12)
    at doListen (net.js:1471:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  code: 'EADDRNOTAVAIL',
  errno: 'EADDRNOTAVAIL',
  syscall: 'listen',
  address: '192.168.1.100',
  port: 3000 }

this the package.json

{
  "name": "Edel",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "next": "^7.0.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  }
}

Upvotes: 4

Views: 14219

Answers (1)

frsechet
frsechet

Reputation: 790

There can be tons of reasons why 192.168.1.100 is refused here, and it is hard to answer without knowing a bit more about your setup. Most likely, your router assigned your computer a local IP that is not specifically 192.168.1.100 but can be anything in the 192.168.1.* range, which makes this address not available on your network (and even less on your computer).

However, the fact you ask this under "node.js" and not "networking" tells me that your real problem is probably rather "how can I expose my local, development next.js server to internet somehow". The long, correct answer is a bit complicated (and probably involves something along the lines of "don't do this for production stuff"), but there is a shortcut for development purposes: - don't try to mess with the hostname setting of next.js, leave it as default (probably 0.0.0.0 or localhost or 127.0.0.1, with a port of 3000) - once your local server launches, try ngrok, which will seamlessly (and for free) create a tunnel to your local development environment.

I may be completely wrong in the second part of my answer, but in that case, please explain a little bit more about what you are trying to accomplish. Long story short: there is little chance that what you really want is bind your next.js to a 192.168.x.x address. :-)

Upvotes: 3

Related Questions