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.
Steps to reproduce the behavior:
npx create-next-app
"dev": "NODE_OPTIONS='--inspect' next"
to scriptsnpm run dev
The node inspector starts normally without crashing the Next process.
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.
Most helpful comment
Just updated the PR for that to solve it.