Waiting for debugger to disconnect... - Node.js in VSCode

45,182

Solution 1

click on the button as shown below to open launch.json-

To open Launch.json

Give your correct file name here, where your server is starting. In my case it is app.js

"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "runtimeVersion": "10.21.0", 
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}/app.js"
    }
]

runtimeVersion is optional, its required if you want to run it on a specific node version.And that node version should be installed on your system.

Solution 2

I found a syntax error in my code. The problem was that I wasn't catching the exception. Using VS Code, I just ticked "Uncaught Exceptions" and found the faulty code.

Solution 3

You should make sure the tab showing problems is empty, i.e., you should address all problems. In cases where the problems are from the files in node_modules, the problems go away just by closing those windows.

For example in the following pictures, there are 4 issues in Problems tab. Fixing them will make the debugger to work correctly!

enter image description here

Solution 4

Use $'{file} for active window:

{

  "version": "0.2.0",
  "configurations": [{
    "type": "node",
    "request": "launch",
    "name": "Active window",
    "program": "${file}"
  }]
}
Share:
45,182
csforbes
Author by

csforbes

Updated on July 14, 2022

Comments

  • csforbes
    csforbes almost 2 years

    I'm trying to step through a simple javascript example in Visual Studio Code, but the debugger hangs trying to disconnect.

    macOS Sierra version 10.12.6

    VSCode version 1.18.1 (up to date)

    Node.js v8.9.2 (up to date) installed with Homebrew

    Debugging with inspector protocol because Node.js v8.9.2 was detected.
    node --inspect-brk= /*(port)*/ jsSandbox.js 
    Debugger listening on ws:// (ip address)
    Debugger attached.
    Waiting for the debugger to disconnect...
    

    This seems like it's been a closed issue with both Code and Node already, which is why I'm so confused. Am I doing something wrong?

    Here is the only javascript file I'm trying to debug:

    // learning about closure
    
    function increase() {  // — gets called once
        var getBig = 0;
        return function() {  // — — gets called each time 
            getBig += 1;      // — — increments each time
            console.log(getBig);
        };
    }
    var bigOne = increase(); // --  a reference to the instance of the function
    bigOne(); //1
    bigOne();//2 
    

    ...and the project's launch.json config:

            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "program": "${workspaceFolder}/jsSandbox.js",
                "console": "internalConsole"
            }