Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Debugger & Typescript: Step Over/Into goes to JS file

I'm new to VSCode and I use it for debugging node.js(Typescript) code. Something that I notices it that if my code stops in a breakpoint and then I use the option "Step Over" or "Step Into", the code goes to the post-compiled Javascript file, instead of the relevant Typescript file.

Do you know how to make the debugger go only to Typescript files as a result of using "Step into" / "Step over"?

My settings.json file look this way:

{
            "type": "node2",
            "request": "launch",
            "name": "Launch TS Program",
            "program": "${workspaceFolder}\\app.ts",
            "preLaunchTask": "tsc: build - tsconfig.json",
            "outFiles": [
                "${workspaceFolder}\\**\\*.js"
            ],
            "smartStep": true,
            "outputCapture": "std",
            "console": "internalConsole",
        },
like image 227
CrazySynthax Avatar asked Mar 28 '19 11:03

CrazySynthax


People also ask

Does VS Code have a debugger?

One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile, and debug loop.

How do I debug in VS Code?

Open a file to debug (either package main source file or the test file) in the editor, and select the Run and Debug button from the Run view. Alternatively, you can start debugging using Start Debugging (F5) command from the Run menu or from the Command Palette (Linux/Windows: Ctrl+Shift+P, Mac: ⇧+⌘+P).

How do I use VS Studio debugger?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.


2 Answers

Try to set smartStep to true in your launch config file (launch.json).

You can find more information about this option in the documentation here.

With the smartStep attribute set to true in a launch configuration, VS Code will automatically skip 'uninteresting code' when stepping through code in the debugger. 'Uninteresting code' is code that is generated by a transpiling process but is not covered by a source map so it does not map back to the original source.

like image 75
Diogo Rocha Avatar answered Oct 19 '22 01:10

Diogo Rocha


I had the same issue. I set the following option in my tsconfig.json and then deleted the directory specified by outDir in tsconfig.json.

{
  ...
 "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
  ...
}

Then when the project was rebuilt on the next debug, the stepping operations seemed to work fine.

like image 33
Aash Avatar answered Oct 19 '22 02:10

Aash