Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio code - cannot connect to runtime process timeout after 10000 ms

I was trying to launch the program from the debug console in VS Code but got the error on cannot connect to runtime process timeout after 10000 ms

launch.json

   "version": "0.2.0",
    "configurations": [

        {
            "type": "node",
            "request": "attach",
            "protocol": "inspector",
            "name": "Attach by Process ID",
            "processId": "${command:PickProcess}"
        },
        {
            "type": "node",
            "request": "attach",
            "protocol": "inspector",
            "name": "Attach",
            "port": 9229
        },
        {
            "type": "node",
            "request": "launch",
            "port":9230,
            "name": "Launch Program",
            "program": "${workspaceFolder}\\bin\\www"
        }
    ]
}

I am trying to debug with VS Code but got hit by the error as below. Am I configuring my launch.json correctly ?

Error Screenshot

like image 262
jdotdoe Avatar asked Apr 29 '18 03:04

jdotdoe


2 Answers

A "launch"-type configuration doesn't need to specify a port. When you set the port parameter, it assumes that your launch config will include the --inspect parameter with that port.

If you have to specify the exact port for some reason, then you can include the --inspect parameter like:

    {
        "type": "node",
        "request": "launch",
        "port":9230,
        "runtimeArgs": ["--inspect=9230"],
        "name": "Launch Program",
        "program": "${workspaceFolder}\\bin\\www"
    }

But I recommend just removing "port" from your launch config.

like image 162
Rob Lourens Avatar answered Sep 22 '22 16:09

Rob Lourens


I'm using nodemon and babel to start visual studio code and found that you need to make sure you have a configuration in package.json and launch.json that are compatible with visual studio code.

Really, that means that you need to find a configuration that allows you to launch your regular configuration from powershell as well as gitbash in windows. Here's what I came up with:

In package.json

  "scripts": {
    "start": "nodemon --inspect --exec babel-node -- index.js",
  },

In launch.json

{
    "version": "0.2.0",
    "configurations": [{
        "type": "node",
        "request": "launch",
        "name": "Launch via Babel (works)",
        "cwd": "${workspaceRoot}",
        "port": 9229,
        "program": "",
        "runtimeExecutable": "npm",
        "console": "integratedTerminal",
        "runtimeArgs": [
            "start"
        ]
    }
    ]
}

When node starts you should see something like:

PS F:\noise\bookworm-api> cd 'F:\noise\bookworm-api'; & 'F:\applications\nodejs\npm.cmd' 'start'

> [email protected] start F:\noise\bookworm-api
> nodemon --inspect --exec babel-node -- index.js

[nodemon] 1.18.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node --inspect index.js`
Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Running on localhost:3333

The thing you're really looking for is:

Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e

This output shows that your debugger is waiting on a WebSockets request on port 9229. You communicate that to visual studio code with:

"port": 9229,

In your launch.json file.

If you don't see the port that the debugging server is waiting on then you probably need to add the --inspect flag to your start command in node.

like image 34
jarederaj Avatar answered Sep 23 '22 16:09

jarederaj