'How to debug TypeScript in Visual Studio Code
- Installing ts-node and typescript locally √
- Add a launch.json file √
{
"name": "Current TS Tests File",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": ["-r", "ts-node/register", "${relativeFile}"],
"cwd": "${workspaceRoot}",
"protocol": "inspector"
}
Open up index.ts
, and start the debugger...
Process exited with code 1
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
Solution 1:[1]
There is two common options for this.
Use NodeJS:
NodeJS only interprets JavaScript, therefore you will have to cross compile your TypeScript first and enable source maps to use breakpoints. VSCode docs have a thorough tutorial for this.
Use Deno:
Deno interprets TypeScript, therefore it does not require cross compilation. VSCode does not support Deno out of the box, but there is an extension for it, and note that you also need Deno CLI in order for it to work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dorin Botan |