Typescript Debugging in VSCode logo

Typescript Debugging in VSCode

Free

Debug Node.js TypeScript apps effectively in VSCode

FreeFree tier
Type
Open Source

About Typescript Debugging in VSCode

A comprehensive guide for setting up debugging of Node.js applications written in TypeScript using Visual Studio Code. It covers configuring TypeScript with source maps (tsconfig.json), creating an automated build task in VSCode (tasks.json), and setting up a launch configuration (launch.json) for debugging. The approach compiles TypeScript to JavaScript before debugging, as an alternative to using ts-node directly. The guide is written by Stefan Baumgartner and includes specific version references (Node 9.8, VS Code 1.21, TypeScript 2.7).

Key Features

Step-by-step setup of TypeScript configuration with source maps (tsconfig.json)
VSCode build task configuration for automatic compilation before debugging
VSCode debug configuration (launch.json) including preLaunchTask, program, and outFiles
Uses compile-then-debug approach for reliable debugging
Explains necessary TypeScript compiler options (sourceMap, esModuleInterop, outDir)

Pros & Cons

Pros
  • Clear, step-by-step instructions with code examples
  • Covers essential configuration files (tsconfig, tasks.json, launch.json)
  • Automates TypeScript compilation before debugging
  • Uses source maps for accurate line mapping in debugger
Cons
  • Guide is dated (2018) and references older versions (Node 9.8, VS Code 1.21, TypeScript 2.7)
  • Requires manual setup of multiple configuration files
  • Does not cover ts-node or other modern debugging alternatives

Best For

Debugging Node.js applications written in TypeScriptSetting up a development workflow with VSCode for TypeScript/Node projectsLearning how to combine TypeScript compilation and debugging in VSCode

FAQ

Why does the guide compile TypeScript before debugging instead of using ts-node?
The author attempted ts-node but encountered issues; switching to a compile-then-debug approach with source maps provided a reliable debugging experience.
What are the key TypeScript compiler options needed for debugging?
sourceMap must be true to allow VSCode to map generated JavaScript to TypeScript sources. outDir specifies the output folder (e.g., './bin'). esModuleInterop can be set to true for easier import handling.
How do I set up an automated build task in VSCode?
Use Ctrl+Shift+B (or Cmd+Shift+B on Mac) to show build tasks, then select 'typescript' and click the gear icon to create a tasks.json file with the TypeScript tsconfig option and problem matcher.