Debugging TypeScript from VSCode

Launch a .ts file from VSCode, attach the debugger.

TL;DR: that’s what it looks like

VSCode launch.json config

Here’s how to do it:

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch current file w/ ts-node",
"protocol": "inspector",
"args": ["${relativeFile}"],
"cwd": "${workspaceRoot}",
"runtimeArgs": ["-r", "ts-node/register"],
"internalConsoleOptions": "openOnSessionStart"
}
]
}

Debugging a single mocha test

The same approach, launching an individual .ts file (the one currently being open in the editor), with mocha and ts-node:

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch current file w/ mocha",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"env": {
"TS_NODE_PROJECT": "src/tsconfig.specs.json"
},
"args": [
"--ui",
"tdd",
"--timeout",
"4000",
"--colors",
"--require",
"ts-node/register",
"${relativeFile}"
],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

Attributions

Big shout out to Russell Briggs for discovering this!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.