I have docker compose in a linux machine. The docker images are build out of node JS source code sitting in the same machine. My IDE is VS Code, but it is running on a different machine(Windows). I have configured Remote SSH so that the IDE in windows machine can browse through the source code in the linux machine using SSH connection. This setup is working fine for me.
But I have a need to do remote debugging of the app running in the docker. I am able to attach the debugger to the process, but when I add break point, it says 'Unbound breakpoint'. I think it is because the debugger is unable recognise the source code sitting in the remote machine.
The following is the launch.json config:
{
"type": "node",
"request": "attach",
"name": "Test",
"protocol": "auto",
"port": 4001,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/src",
"skipFiles": [
"<node_internals>/**/*.js"
]
}
How can add a properly 'bound' break point?
Related
I'm using VSCode to debug a node.js script running on a remote linux server on my LAN. I'm using the RemoteSSH plugging to access the scripts, save, and edit it. I can also run it from the VSCode just fine. But I tried to use this article here to setup remote debugging:
https://dakshika.medium.com/remote-debug-node-js-application-using-visual-studio-code-dc0fa0b4dec4
I did modify the commandline command to start the node.js debugger since my server has an older version of Node (Node 8.10.0). I have to use the following:
node --inspect-brk=127.0.0.1:9229 scripts/myScript.js
After running the command, it shows that node is listening for connections. But when I run my Attach launch configuration:
"version": "0.2.0",
"configurations": [
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 9229,
"address": "127.0.0.1",
"restart": false,
"sourceMaps": false,
"continueOnAttach": true,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
it doesn't do anything. The run/pause/stop buttons come up but it doesn't jump to the first line of code so I can step through. Any idea what could be going on?
I am trying to remotely debug NodeJs application, which uses clusters. When I run my app locally, and I am attaching to it, VS Code see child processes and breakpoints works:
VS Code Config:
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 50131,
"internalConsoleOptions": "neverOpen",
"skipFiles": ["<node_internals>/**"],
"autoAttachChildProcesses": true
},
VS Code result:
However, in remote host, process starts same way, same port, I am able to attach debugger to it, but VS Code Can't see child processes and source maps (to connect local files breakpoints to remote, in debug config I have correct host address):
So the difference between local env and remote is Windows vs Unix, and in remote app is run via Forever (module, however, even Forever, without clusters remote debugging works correct).
Where can be an issue?
EDIT: I can't use SSH debug in my organization.
Give vscode extension Remote SSH a try. It let you run remote code locally.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh
I'm trying to debug my remote node server through VSCode and it doesn't stop on any of the breakpoints i've configured.
I'm running VSCode on my mac where i have one copy of the node project and i have another copy of the same node project on a remote machine, both copies of the node project are synced.
i'm running the node server on the remote machine using the following command:
sudo node --inspect=5858 app.js
and my VSCode launch.json configurations are as follow:
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "remote server addr",
"localRoot": "${workspaceFolder}",
"remoteRoot": "the path to project directory on remote server",
"protocol": "auto"
}
When i launch the debugger on VSCode it seems like it connects to the remote server but it doesn't stop at any of my breakpoints.
VSCode version is 1.28.1
Node version is 9.11.2
What am i missing?
I found the solution to my question the configuration i was missing is server=4771
when i run my app as follow:
sudo node --inspect=5858 app.js server=4771
VSCode debugger is able to debug my remote node server, more details about it are mentioned here: https://code.visualstudio.com/docs/extensions/example-debuggers
I get error:
Cannot connect to runtime process, timeout after 10000ms - (reason: cannot connect to the target)
NodeJs v4.3.1 run on WSL.
The below is my launch.json
"type": "node",
"request": "attach",
"name": "Attach to WSL",
"port": 3000,
"address": "localhost",
"restart": true,
"protocol": "inspector",
"localRoot": "${workspaceFolder}/web-frontend",
"remoteRoot": "/mnt/c/workspace/.../web-frontend"
WSL uses the path from Windows so localRoot and remoteRoot are the same.
What am I missing so far?
I created a VS Code extension: WSL workspaceFolder, which will help you to automatically set the remoteRoot in your launch.json to the correct WSL path. For example my launch.json, based upon your file paths would look like below;
/vscode/launch.json
{
// 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": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "localhost",
"port": 5858,
"localRoot": "${workspaceFolder}/web-frontend",
"remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}/web-frontend"
}
]
}
Then to start a debug session, in the WSL terminal enter NODE_ENV=debug node --nolazy --inspect-brk=5858 before the path to the script you wish to debug.
However, you may run into problems using Node v4 because it does not support the 'inspector protocol'. I would strongly recommend you upgrade to a more recent version of Node. Currently v8 is the latest LTS version: Node.js releases
I tried to use the simple node.js example visualstudio code provides, but unfortunately when node is being started from visual studio code (on OS X) the node gets started with some arbitrary debug-brk, but debugger attachment fails.
When I run the node app manually with --debug-brk = 5858 and then use the attach I can debug my app. Anyone faced the same problem?
P.S I got mono installed from the mono project page .pkg
Here is my launch.js:
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "./bin/www",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
Just ran into the same issue... Code couldn't find Node.
Change this line to point to your executable, for example:
"runtimeExecutable": "C:/Program Files/nodejs/node.exe",
Enjoy!
Might be the cluster thing. Try to turn off cluster in ./bin/www, and you will be able to debug it.