question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use breakpoints to debug TypeScript in Visual Studio Code.

See original GitHub issue

Issue

I’m unable to debug Jest test cases written in TypeScript. Possibly just a configuration problem? What am I missing? Thanks!

Steps to reproduce

  1. Install Visual Studio Code. I tested with version 1.11.2
  2. Install Node.js. I tested with 7.8.0.
  3. Clone the repo here
  4. run npm install or yarn
  5. Set breakpoint on line 6 of SystemUnderTest.spec.ts. (Just above debugger; statement)
  6. Set breakpoint on line 3 of SystemUnderTest.ts. (Inside constructor).
  7. Press F5 or click “Start Debugging”.

Expected Behavior

Debugger should stop…

  1. On line 6 of SystemUnderTest.spec.ts.
  2. On line 3 of SystemUnderTest.ts.
  3. On line 7 of SystemUnderTest.spec.ts.

Actual Behavior

Debugger only stops on line 7 of SystemUnderTest.spec.ts

Additional observations

debugger statements stop in the proper location in the TS files, not in the transpiled JS, so sourcemaps are being emitted and consumed. Once stopped, VS Code debug controls (e.g. F10 to step over) work fine. VS Code reports that the breakpoints are loaded. They are not greyed out.

breakpoints

However, as the debugger reaches each expected breakpoint but doesn’t it it, it will begin reporting a source map problem.

sourcemaps

The “future” breakpoint (line 8 of SystemUnderTest.spec.ts) does not report any sourcemap problem.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

12reactions
zenVentzicommented, Jul 8, 2019

Hours spent on issues like that make me proud to be a software engineer. Bill Burr + Louis C.K. and still can’t laugh as loud. I’m also going to like my own comment for the added effects

9reactions
jcgillespiecommented, Jun 17, 2017

@netpoetica Here’s mine, which I use on this project I use a separate jest config for debugging. launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug Tests",
            "preLaunchTask": "debugBuild",
            "program": "${workspaceRoot}\\node_modules\\jest\\bin\\jest.js",
            "args": [
                "--runInBand",
                "--config",
                "${workspaceRoot}\\config\\jest.debug.json"
            ],
            "sourceMaps": true,
            "outFiles": [
                "${workspaceRoot}/output/debug/**/*"
            ]
        }
    ]
}

tasks.json

{
    "version": "0.1.0",
    "command": "yarn",
    "isShellCommand": true,
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "build",
            "showOutput": "never",
            "args": [
                "run",
                "build"
            ],
            "isBuildCommand": true
        },
        {
            "taskName": "debugBuild",
            "showOutput": "never",
            "args": [
                "run",
                "build:debug"
            ]
        }
    ]
}

Relevant related files are here: package.json jest.debug.json tsconfig.debug.json Hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio code breakpoint not working on Node.js using ...
1 Answer 1 · Add the start script to package.json · click on the debug menu icon on the left side navigation menu....
Read more >
TypeScript debugging with Visual Studio Code
Whenever you set a breakpoint in the original source, VS Code tries to find the generated source by searching the files specified by...
Read more >
Debug Typescript Not Stopping on Break Points - Electron
I am attempting to debug an electron app written in Typescript and compiled to JS/sourcemaps with gulp and debugged with VSCode.
Read more >
Debug a JavaScript or TypeScript app - Visual Studio (Windows)
You can debug JavaScript and TypeScript code using Visual Studio. You can hit breakpoints, attach the debugger, inspect variables, view the call ...
Read more >
TypeScript Debugging Inside VSCode
In order to do that we need to have mappers, that map our TS files to the JS ones, and using those mappers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found