I am getting an error while debugging nodejs in vscode: Can not connect to runtime process, timeout after 10,000 ms - (can not connect to the target)
enter image description here
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": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\server\\js.js"
}
]
}
Why am I getting this error? And how can I fix it?
Related
This is my first time use debugger on Visual Studio Code. I am working on a asp.net-react webapi. I was easily able to use debugger for .net Core. Here is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/API/bin/Debug/net6.0/API.dll",
"args": [],
"cwd": "${workspaceFolder}/API",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\bNow listening on:\s+(https?://\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
Then I wanted to use debugger for node. I watched some videos from youtube but none of them worked. I also followed this link https://code.visualstudio.com/docs/editor/debugging, followed his steps but I nothing worked. I tried on launch, on attach, but the debugger doesn't even start. I added a onlaunch configuration:
{
"name": "Launch Program",
"program": "${workspaceFolder}/app.js",
"request": "launch",
"skipFiles": [ "<node_internals>/**" ],
"type": "node"
},
and it threw me this error on debug console:
C:\Program Files\nodejs\node.exe .\app.js
Process exited with code 1 Uncaught Error
Error: Cannot find module
'c:\Users\Lenovo\Desktop\Student\app.js' at
Module._resolveFilename (internal/modules/cjs/loader:933:15) at
Module._load (internal/modules/cjs/loader:778:27) at
executeUserEntryPoint (internal/modules/run_main:77:12) at
(internal/main/run_main_module:17:47)
No debugger available, can not send 'variables'
When I use onattach configuration:
{
"name": "Attach",
"port": 3000,
"request": "attach",
"skipFiles": [ "<node_internals>/**" ],
"type": "node"
},
it doesn't even throw any error, nor start debugging.
I googled and tried so many ways and nothing worked. Can anybody explain what should I do.
Thank you.
When I am debugging my python code it skips over code not written by me. I've set justmycode to false and I've tried updating request however, it won't accept any values except launch or attach and purpose is set to debug-test. Nothing seems to work.
My JSON file:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode":false,
"purpose": ["debug-test"]
}
]
}
The message from the debugger(yes, I stepped in not over):
Frame skipped from debugging during step-in.
Note: may have been skipped because of "justMyCode" option (default == true). Try setting "justMyCode": false in the debug configuration (e.g., launch.json).
Sorry if this a stupid question I am a newbie and feeling totally over my head in my internship.
Literally this is my entire code. The message from the debugger appears when I try to step into execute().
pQuery=p.logquery()
pQuery.execute()
I had a similar problem just now and it suddenly started working when I set the justMyCode option to the end of the configuration without a comma at the end of the line.
So, not working:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
}
]
}
And working example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
I cannot fathom why this is the case. If this works for you as well, please let me know.
The official docs on how to do it are here.
The OP was specifically adding a launch configuration for debugging tests. However, over here it's mentioned you should set "request": "test" for "for justMyCode to work with test debugging".
{
"name": "Python: Debug Tests",
"type": "python",
"request": "test",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false
}
Which is not so clearly explained in the official docs... but worked for me.
Whenever I try to run the debugger, I keep getting this error:
This is the debug configurations:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server/bin/www",
"envFile": "${workspaceRoot}/server/.env"
}
]
}
---- Update ----
I am using VScode version 1.49.0
As #S.Clarke876 mentioned, it appears to be a bug in VS Code, that should be fixed in the next release. See: https://github.com/microsoft/vscode/issues/106484#issuecomment-691202789
You can work around the issue by adding "outputCapture": "std" to your launch.json file.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server/bin/www",
"envFile": "${workspaceRoot}/server/.env",
"outputCapture": "std"
}
]
}
Worked for me! It only appeared to happen when the npm package debug attempted to write out to the console. I.e. console.log was fine.
Thanks again, #S.Clarke876! Only adding this answer as I nearly missed your comment.
In Visual Studio Code, in the launch.json file that launches the app I'm writing, how do I add command line arguments?
As described in the documentation, you need to use the args attribute. E.g.
{
// 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": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/main.js",
"args": ["arg1", "arg2", "arg3"]
}
]
}
I pass arguments by this way for the python program, it may work for nodejs:
{
"type": "node",
"request": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/main.js",
"args": ["--arg1", "value1", "--arg2", "value2"]
}
I am trying to use the vs code debugger for my node.js application and all the commands and code but when i apply the break point it goes back to the main files and function of the nodejs and npm files instead of going back step by step to the service and then storage, brake points not working properly for my apis any body can help
{
// 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 by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app/app.js"
},
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 9229
},
{
"type": "node",
"request": "launch",
"name": "My Debugger",
"program": "${workspaceFolder}\\index.js"
}
]
}
Have you tried attaching to a node process?
Step 1: Run the code.
Step 2: Press CMD + SHIFT + P then search for "Attach to Node Process" and it will list the running processes.
Step 3: Choose the process you want to attach to.
This enables debugging.