M. Farnik
M. Farnik

Reputation: 275

Can't debug node.js using Chrome DevTools

When I run node --inspect app.js it says "Debugger attached". Then I open up chrome://inspect and I see my app running there so I click either Open dedicated DevTools or Inspect (next to the app's name). No matter how I open Node DevTools though, it just doesn't seem to be connected to anything (I can't see the source code there, the debugger statements are ignored, nothing logs to the console etc). I also tried opening it by opening regular DevTools and clicking the green Node icon.

It's weird because Chrome clearly sees the server running and something is clearly connecting to Node (and I don't think there's anything else on my network that could do that) but I still can't get DevTools to even acknowledge the server's existence.

I also distinctly remember debugging something the same exact way a few weeks ago and back then everything worked fine (although I remember I also struggled with this a bit but I somehow got it to work at the end, I think attaching the name of the file at the end of the command instead of in putting it in the middle did the trick at the end). The only thing that's happened since then is that I updated from v8 to v10 (LTS)

I've obviously tried rebooting and also reading every manual and article about node --inspect out there, nothing helped.

Upvotes: 4

Views: 5922

Answers (4)

HelloWorld101
HelloWorld101

Reputation: 4366

Chrome version: 92

For me, the problem was The Chrome DevTools was not looking for the connection port my Node.js process was using.

I did the following:

  1. Start the node process with --inspect flag. It started the process on port 9239.
  2. Type chrome://inspect/#devices in Chrome address bar.
  3. Click "Open dedicated DevTools for Node" in the devices page.
  4. It opens the "DevTools-Node.js" window.
  5. Click the "Connection" tab.
  6. Click "Add connection" button.
  7. Type localhost:9239 in the text box and click "Add".

After adding the correct port, the DevTools connected to the Node.js process and I was able to debug it.

Upvotes: 7

NIKHIL MALIK
NIKHIL MALIK

Reputation: 19

use command instead of node --inspect:-

node --inspect-brk

Upvotes: 2

Vinayak
Vinayak

Reputation: 31

I was facing same problem, I have solved it by

1) Updated chrome to latest version and relaunched it

2) Restarted node --inspect server.js

3) Noted port number as shown here port number

4) Opened chrome://inspect and added localhost: port number noted in step 3 update connection in chrome

Upvotes: 2

rambino
rambino

Reputation: 1

Seems to be a new chrome issue: https://github.com/nodejs/node/issues/26887

Upvotes: 0

Related Questions