VSCode Version: 1.10.2 OS Version: Windows 7 Profesionnal, SP1 Node version: 6.10.0
Hi everyone.
I'm trying to debug typescript code (or javascript code) in server side with visual studio code, when launching it with nodemon. I've added a new configuration in launch.json which looks like this:
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--debug=5858"
],
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"]
}
I have a task in vscode that is running tsc that builds javascript files properly. This is my current task config:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
The javascript files are generated as expected when I change a typescript file. And the nodejs server is restarting as expected when a javascript file is generated.
But I am not able to break on any breakpoint (on typescript files or javascript files).
Can you tell me please if it is an issue or if there is something I am missing ?
Thank you for your help
It looks that there is an issue in vscode (Issue opened by on github [here][1]) . But for now, the workaround is to set the protocol in the configuration (launch.json) to "inspector". With this option, the breakpoints is now reached properly.
Also, change the "--debug=5858" in the "runtimeArgs" option to "--inspect=5858"
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
"runtimeArgs": [
"--inspect=5858"
],
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"],
"sourceMaps": true
},
Also, after that, if you have a flashing message error telling you:
Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858)
It means that your program is too short and that debugger has not enough time to break on your breakpoint. To resolve that, add a second runtime argument to option "runtimeArgs": "--debug-brk" and set too "stopOnEntry" option to true
The final configuration should looks like this:
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
"runtimeArgs": [
"--inspect=5858",
"--debug-brk"
],
"stopOnEntry": true,
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"],
"sourceMaps": true
}
It should break on the first line of your entry javascript file. Then you can press F5 and it will reach your own breakpoint.
If you don't want to press F5 each time you run your program, you can instead embed your main entry code inside a setTimeOut function with at least 1000 ms of timeout.
All these options will give enough of time to vscode to break on your breakpoints.
://github.com/Microsoft/vscode/issues/23900 "GitHub Issue"