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

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 ?

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.

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'
> bookworm-api#1.0.0 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.

I get this same error when I forget to close the browser from the last debug session. It holds on to the connection to the Angular proxy and prevents a new debug session from starting up. Once I close the browser, F5 starts up a new session without error.

duplicate Google Chrome shortcut → itest
press alt key doubleclick itest
itest Properties → Shortcut → Target :
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=6062 --user-data-dir="%appdata%\Google\Chrome\itest
VS Code, Menu Debug → Add Configuration → Chrome: Attach → "port": 6062, → Ctrl+Shift+D Debug → Switch Attach to Chrome → Start Debugging

Delete launch.json file and go to debug and create new launch.json file

Open Android Studio, Configure, ADV Manager, create or open an ADV.
In VS Code and in debug click emulate android cordova
Command line - cordova emulate android
{
"name": "cordova emulate android",
"type": "cordova",
"request": "launch",
"platform": "android",
"target": "emulator",
"port": 9222,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
// "ionicLiveReload": true
},

I am using docker-compose to run a react express app. You can see the full compose file below.
I got the mentioned error, and I added a port mapping as follows to resolve the issue.
- "9229:9229"
Also the if you are using visual studio code, the address configuration in launch.json file inside of .vscode should be as follows.
"address": "0.0.0.0",
The full launch.json file is pasted below as well.
The full docker-compose.yml file looks as follows.
version: '3'
services:
proxy:
build:
context: ./proxy
ports:
- 7081:80
redis-server:
image: 'redis'
node-app:
restart: on-failure
build:
context: ./globoappserver
ports:
- "9080:8080"
- "9229:9229" ######### HERE IS THE FIX ##########
container_name: api-server
ui:
build:
context: ./globo-react-app-ui
environment:
- CHOKIDAR_USEPOLLING=true
ports:
- "7000:3000"
stdin_open: true
volumes:
- ./globo-react-app-ui:/usr/app
postgres:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
- ./init-database.sql:/docker-entrypoint-initdb.d/init-database.sql
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
postgres:
Here is the launch.json file.
Take a look at this reference for this file settings.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "3",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach", // The other option is launch
"port": 9229,
//"address": "localhost",
"address": "0.0.0.0",
//"localRoot": "D:\\Vivek\\MxWork\\Js\\GloboClientServer\\src\\globoappserver",
"localRoot": "D:/Vivek/MxWork/Js/GloboClientServer/src/globoappserver",
"remoteRoot": "/app",
"protocol": "inspector",
"skipFiles": [
//"<node_internals>/**",
"<node_internals>/**/*.js",
"${workspaceFolder}/**/node_modules/**/*.js"
]
//"program": "${workspaceFolder}\\src\\globoappserver\\index.js"
}
]
}

Go to Tools -> Options -> Debugging -> General
then disable
I'm using it successfully with the following options disabled.
In Visual Studio go to: Tools -> Options -> Debugging -> General
Enable JavaScript debugging for Asp.Net (Chrome, Edge, and IE)
Enable Legacy Chrome JavaScript debugger for ASP.NET.

In my case updating the core tools solved the issue.
Use the below command to update:
npm install -g azure-functions-core-tools

Related

while debugging in vscode changes in nestjs file does not take effect

I have a nestjs project in vscode and in debugging mode the changes in code does not take effect. Breakpoints hit normally, however, but for example a changed variable values are not to be seen - i.e. they stay as the previous ones (the ones before change).
My launch.json is the following:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"runtimeExecutable": "nodemon",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register", "--config", "nodemon-debug.json"],
"program": "${workspaceFolder}/src/main.ts",
"autoAttachChildProcesses": true,
"restart": true
}
]
}
And the nodemon-debug.json file has the following:
{
"watch": ["src"],
"ext": "ts, js",
"ignore": ["src/**/*.spec.ts"]
}
And strangely enough, when I make change in the code, the nodemon really registers it and restart the app, as can seen from the console:
C:\...\AppData\Roaming\npm\nodemon.cmd --nolazy -r ts-node/register --config nodemon-debug.json .\dist\main.js
[nodemon] 2.0.18
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] to restart at any time, enter `rs`
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] watching path(s): src\**\*
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] watching extensions: ts,js
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[nodemon] starting `node --nolazy -r ts-node/register .\dist\main.js`
c:\...\AppData\Roaming\npm\node_modules\nodemon\lib\utils\log.js:34
[WEB] http://localhost:3000
Can anyone figure out why changes are not taking effect?
I finally found solution from this https://stackoverflow.com/a/63325135/7625979
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"start:debug",
"--",
"--inspect-brk"
],
"autoAttachChildProcesses": true,
"restart": true,
"sourceMaps": true,
"stopOnEntry": false,
"console": "integratedTerminal",
}
]
}
This solution indeed works for me perfectly and does not need either the vscode's setting: Debug > Javascript: Auto Attach Filter to "Always". Also console: integratedTerminal -option is handy because debug-info comes directly into the same console. Also, nodemon-debug.json is not now needed.
Script command in Package.json file are now:
"scripts": {
...
"start:debug": "nest start --debug --watch",
...
}
It seems that "--watch" is still needed here for the code changes to take effect.
I don't have a launch.json in my NestJS project in VSCode.
However, I did change the debug settings in VSCode to the following:
file -> preferences -> settings -> Debug > Javascript: Auto Attach Filter to "Always"
Then when I set a breakpoint my test stops on the breakpoint. If I make a change and save the file my test will restart automatically and stop on the breakpoint with the updated values.

Nodemon Inspect address already in use when refresh with vscode debugger

I am debugging a node application in Visual Studio, so I have to attach create a new configuration in launch.json:
{
"type": "node",
"request": "attach",
"name": "Debug API",
"remoteRoot": "/workspaces/telehealth/projects/api",
"localRoot": "${workspaceFolder}/projects/api",
"protocol": "inspector",
"port": 9229,
"restart": true,
"address": "localhost",
"skipFiles": ["<node_internals>/**"]
}
And the script in package.json is
nodemon -e js,gql --watch dist --watch typeDefs --delay 500ms --inspect=0.0.0.0:9229 ./dist/index.js
That works fine the first time, but when I save a file and the server restarts, it fails with the classical error address already in use because the debugger is running.
I have to turn off the debugger, wait 5 seconds and then save the file to restart the server. After that, I have to start the debugger again.
There should be a way to restart without stopping the running process to debug, but I couldn't find nothing

Cannot find Node process using VSCode Debugger

I'm testing out the VS Code node debugger, but I'm not able to find any node processes when trying to attach to a running process.
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
}
]
}
the contents of my package.json file:
"scripts": {
"start": "node --inspect=0.0.0.0:9229 ./bin/www"
}
After I start up the process using 'npm start', I press 'start debug' and the list of node processes is:
1 sssd_pam
1 sssd_nss
1 sssd_be
Looks like this and none of these are the server I just launched.
This list persists even after I take down the node server.
Why am I not able to see any of my running node processes in the VSCode process attach?
P.s. I'm closely following this tutorial on debugging Node.js with VS Code.
Are you running the NodeJS in debug mode inside npm start? You need to use the --inspect flag. Without this flag, the NodeJS interpreter won't open the debug port to the VSCode to attach to.
Refer to: https://nodejs.org/en/docs/guides/debugging-getting-started/
Another option is to attach using a port definition. I usually do something like this in the launch.json:
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"restart": true,
"sourceMaps": true,
"protocol": "inspector"
}
Then I start the NodeJS process as: node --inspect=0.0.0.0:9229 start.js

VSCode node.js debugging with symlink to another project folder

I have two folders in my project: api and db-service
Api contains the api routes and db-service contains the database logic.
I linked db-service in api with npm link db-service.
When I set breakpoints in db-service and start debugging the api these are ignored (breakpoint set but not yet bound).
However when I set breakpoints in api/node_modules/db-service they work as expected.
To make things more clear, the api runs in a docker-container.
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach API",
"type": "node",
"request": "attach",
"port": 58581,
"address": "localhost",
"sourceMaps": false,
"localRoot": "${workspaceRoot}/api",
"remoteRoot": "/usr/src/app",
"protocol": "inspector"
},
docker-compose.yaml:
version: '2'
services:
api:
build: ../api
command: nodemon -L --inspect=0.0.0.0:58581 --preserve-symlinks
Is there a way to tell vscode to recognize the breakpoints set in db-service?
PS: Another thing I noticed that if I open a file in node_modules/db-service and the same file in db-service they are not automatically refreshed and vscode tells me to merge them.

Debugging NodeJs Program in Docker Container with VSCode in one step

I'm trying to setup my VSCode environment so I can debug my dockerized node.js program in one single step by hitting F5.
Currently my setup is the following:
.vscode/launch.json:
{
"version": "0.1.0",
"configurations": [
{
"name": "Attach",
"type": "node",
"protocol":"inspector",
"request": "attach",
"port": 5858,
"restart": false,
"sourceMaps": false,
"localRoot": "${workspaceRoot}/",
"remoteRoot": "/usr/local/src/my-app"
}
]
}
docker-compose.debug.yml:
version: "3"
services:
app:
build: .
ports:
- "3000:3000"
- "5858:5858"
entrypoint: node --inspect-brk=0.0.0.0:5858 app/entry.js
networks:
- appnet
networks:
appnet:
Now this works w/o any problem when I execute docker-compose -f ./docker-compose.debug.yml up --build in an external terminal, and then run the "Attach" configuration in VSCode.
However I can't find a way to run docker-compose, before attaching to the remote (docker) process from within VSCode. The goal is to be able to just hit F5 and have VSCode launch docker-compose, and automatically attach itself to it.
I've tried calling the docker-compose by using the "Launch via NPM" VSCode configuration and adding
"docker-debug" : "docker-compose -f ./docker-compose.debug.yml up --build"
to my package.json scripts section.
But that only partially works as the debugger seems to ignore the remoteRoot attribute of the config and hence, is completely useless for debugging my program (e.g.: it doesn't accept breakpoints, and the only files it knows how to debug are nodes.js internals...)
Any idea of how I could solve this?
this is works for me, In your launch.json:
{
"name": "Debug Jest",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "debug"],
"address": "127.0.0.1",
"port": 9230,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app/server" # path to your nodejs workspace in docker
},
package.json you run your service:
"scripts": {
"debug": "docker-compose -p dev -f docker-compose-dev.yml up jestdebug"
},
and in docker-compose-dev.yml:
version: '3.4'
services:
jestdebug:
image: node:10.15.3-alpine
working_dir: /usr/src/app/server
command: node --inspect-brk=0.0.0.0:9230 node_modules/.bin/jest --runInBand ${jestdebug_args}
volumes:
- nodemodules:/usr/src/app/server/node_modules
- ../server:/usr/src/app/server
ports:
- '9230:9230' # for debuging
networks:
- backend
depends_on:
- nodejs
tty: true
# ...other services

Resources