Using the following configuration I managed to debug flawlessly Node.js applications written in Typescript using the Visual Studio Code IDE. I have tested it on Mac OS and almost every Linux distro like Debian, Ubuntu, Arch.
Configure tsconfig.json
First of all, enable source maps "sourceMap": true
and declarations "declarationMap": true
, "declaration": true
.
Don't forget to specify the destination folder using the outDir
parameter.
Configure VSCODE
Paste the following snippet and change __MYAPP__
to the typescript file you want to debug and __MYDIST_FOLDER__
to the dist folder of your project.
Don't forget to whitelist (OUTPUT) port 9229 locally on your iptables.
Examples:
__MYAPP__
= src/app.ts
__MYDIST_FOLDER__
= dist
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Node.js",
"program": "${workspaceFolder}/__MYAPP__.ts",
"outFiles": [
"${workspaceFolder}/__MYDIST_FOLDER__/**/*.js"
],
"sourceMaps": true,
"port": 9229,
"runtimeArgs": [
"--inspect-brk=9229"
],
"console": "integratedTerminal"
}
]
}
Support
If you liked this quick guide follow me on Twitter :) https://twitter.com/devcrafter91
Top comments (0)