Visual Studio Debugging

Visual Studio Debugging

Refs

  1. How to debug typescript with VS Code

Debugging Node.js App

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"runtimeExecutable": "nodemon",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal",
"program": "${workspaceFolder}\\main.js"
}
]
}

// If running parameters are required like this:$ python main.py --verbose --name Test:
// add "args" property:
"args": ["--verbose", "--name=Test"]

Debugging Typescript

Example project

1
2
3
4
5
6
7
.
├ .vscode
├ launch.json # Debugger launch configuration file
├ app.ts
├ package.json
├ tsconfig.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Build Project",
"program": "${workspaceFolder}\\app.ts", // Entry file of the app
"preLaunchTask": "npm: build", // Task before launching debug. Calls `build` script of package.json
"sourceMaps": true, // use sourcemaps from `out` folder
"smartStep": true, // skip “uninteresting” code in the debugger (e.g. compiled JS-files)
"internalConsoleOptions": "openOnSessionStart", // open the debug console during a debugging session
"outFiles": [
"${workspaceFolder}/out/**/*.js" // place where the debugger looks for the sourceMap files
]
}
]
}
1
2
3
4
5
// app.ts
const a:string = 'Hello'
const b:number = 42

console.log(a + b)
1
2
3
4
5
6
7
8
// package.json
{
"name": "mytask",
"version": "1.0.0",
"scripts": {
"build": "tsc"
}
}
1
2
3
4
5
6
7
8
9
10
// tsconfig.json
{
"compilerOptions": {
"outDir": "./out",
"rootDir": "./",
"sourceMap": true, // It is important to set the sourceMap-property to true. Sourcemap files are required to map the TypeScript code to the JavaScript code in the debugger later.
"moduleResolution": "node",
"target": "es5"
}
}
Author

Chendongtian

Posted on

2022-09-10

Updated on

2023-08-04

Licensed under

Comments