Next.js: Cannot start node inspector: "address already in use"

Created on 13 Mar 2020  路  4Comments  路  Source: vercel/next.js

Bug report

After upgrading from Next 9.2.2 -> 9.3.0 the node inspector fails to start (crashing the Next process) with the error "Starting inspector on 0.0.0.0:9229 failed: address already in use".

None of the suggestions offered in https://github.com/zeit/next.js/issues/10610 or https://github.com/zeit/next.js/issues/9027 have helped. Have also tested with Next 9.3.1-canary.3 and noted the same issue occurs.

To Reproduce

Steps to reproduce the behavior:

  1. Run npx create-next-app
  2. Add "dev": "NODE_OPTIONS='--inspect' next" to scripts
  3. Run npm run dev
  4. See error

Expected behavior

The node inspector starts normally without crashing the Next process.

System information

  • OS: macOS 10.15.3
  • Version of Next.js: 9.3.0+
needs investigation

Most helpful comment

Just updated the PR for that to solve it.

All 4 comments

I confirm this new behaviour, we need to figure out what are the different actual nodejs processes launched behind the next command and then see how we can fix that. Maybe by re-introducing the --inspect flag instead or manipulating process.env.NODE_OPTIONS (馃槺) in the main cli tool.

I had a look in the next source code but could not figure out what are the actual processes.

Update: I found the issue. When running next dev, the file next-dev-server.ts will launch a subprocess using jest-worker here: https://github.com/zeit/next.js/blob/6997b0236b68fd7c8f5395003c99a719974cc404/packages/next/server/next-dev-server.ts#L83-L91

As a result, another Node.js process is spawned with the same process.env.NODE_OPTIONS='--inspect' and will also try to start a debugger on the same port than the one the main next dev command started just earlier.

This is a known issue from Node.js but there's not much that they will do about it for good reasons, see https://github.com/nodejs/node/issues/9435#issue-186998002

But we can do something, I tried it and it works, just remove any --inspect flag from NODE_OPTIONS passed to the worker and done, see the PR: #11041

Related issue #11095

Just updated the PR for that to solve it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickredmark picture nickredmark  路  60Comments

arunoda picture arunoda  路  103Comments

tomaswitek picture tomaswitek  路  73Comments

matthewmueller picture matthewmueller  路  102Comments

Timer picture Timer  路  90Comments