"Socket hang up" when trying to debug heroku nodejs from vscode - node.js

I'm trying to debug a heroku nodejs from vscode
My launch.json
{
"type": "node",
"request": "attach",
"name": "Heroku",
"address": "localhost",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
My ProcFile
web: node --inspect-brk=9229 ./server.js
Already did a git push with of the ProcFile, then I run
heroku ps:forward 9229
Then I run de debug "Heroku" in VSCode, but it doesn't seem to be connecting, after some time I got the message
"Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target:socket hang up"
But if I click on stop before that message shows the forwarding process in the terminal stops, so not sure if it's connecting or not, or I still need to configure something else
Thanks

Related

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

Debug Node.js with TypeScript and Docker in VS Code: “Breakpoint ignored because generated code not found”

I am trying to debug a dockerized Node.js application written in TypeScript.
I followed a tutorial that says that I should configure Nodemon and expose a port on the app container so the debugger can listen to.
When I run the debugger from VS Code I got a disabled Breakpoint with this message “Breakpoint ignored because generated code not found”.
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Server",
"type": "node",
"port": 9229,
"restart": true,
"protocol": "auto",
"request": "attach",
"remoteRoot": "/server/dist",
"localRoot": "${workspaceFolder}/packages/back/dist",
"skipFiles": ["<node_internals>/**/*.js"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
}
]
}

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

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 ?
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

How to see remote Node js code during remote debug on Visual Studio Code

I digged all the net, but still can't find answer.
I run nodejs code with nginx on a remote VPS.
In the local project folder created the launch.json and can run debug mode on the server with F5 button. Local project folder only has .vscode with launch.json
This is launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "x.x.x.x",
"restart": true,
"sourceMaps": false,
"outFiles": [],
"localRoot": "${workspaceRoot}",
"remoteRoot": "/views/"
}]
}
On a server
[root#tri ~]# node --debug /usr/appfolder/views/index.js
Debugger listening on [::]:5858
Example app listening at http://:::5000
Through ngnix both index.js and css codes are accessible outside the server to the world.
But Visual Studio Code doesn't see this index.js to debug through.
I need to debug through remote code on VPS.
Thank You

Resources