Let’s take a look at how we can configure VSCode’s built-in debugger to debug a TypeScript Node application.
First, you have to install these dependencies (I prefer installing them as dev dependencies):
Generate Source Map
tsconfig.json file by running:
or create the file yourself.
"sourceMap": true to the
tsconfig.json file will now look something like this:
By setting the
sourceMap property to
true. The TypeScript compiler will now also generate a
.map file as well as a
.js file for each of our TypeScript files.
Next, go to the debug tab, and add a JSON configuration file named
launch.json with these contents:
Feel free to change the
name field to anything you like.
The most important part here is
runtimeArgs, which contains optional arguments to be passed to the runtime executable.
"-r" which stands for
require to register
tsconfig-paths is used to load modules whose location is specified in the paths section of
Finally, make sure the
program field points to the entry point of your app.
That’s it. You’re done with the configuration. Now, you can put breakpoints on your code, and click on the start debugging icon or simply press the keyboard shortcut, F5, to debug.