8

I'm trying to debug my typescript NodeJs application in VS Code with the following launch.json:

   {
   "version": "0.2.0",
      "configurations": [
         {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/apps/file-server-app/app.ts",
            "outFiles": [
                "${workspaceFolder}/build/**/*.js"
            ],            
            "runtimeArgs": [
                "--require", 
                "ts-node/register"
            ]
        }
      ]
   }

The application starts fine and everything works as it should except the breakpoints. Instead of stopping on the actual line I placed the breakpoint in the Typescript code, it breaks on the line in the compiled Javascript equivalent.

Things I've tried:

  • Enabling the source maps and making sure they are generated correctly
  • Enabling the in line source maps and making sure they are generated correctly
  • Reinstalling everything on a new setup

Additional information:

VSCode Version: 1.46.1
TypeScript Version: 3.8.3

2 Answers 2

7

Turns out this is intended in the design of VS Code.

To fix it, you can either:

  • Set outFiles in your launch.json to an empty array so that sourcemaps are not discovered and the path redirection doesn't happen.
  • or drop ts-node and debug compiled files, or use ts-node without manually compiling them.

See this github issue for more details: https://github.com/microsoft/vscode/issues/101927

Sign up to request clarification or add additional context in comments.

1 Comment

this is the correct answer
2

Apparently, enabling the allowjs setting in the tsconfig.json and compiling the typescript with that makes the VS Code debugger step into the Javascript files instead of the Typescript files. For now, even if it means you can't error check your javascript files while compiling the typescript, the workaround is to disable the allowjs setting by setting it to false like this:

"compilerOptions": {
    //"allowJs": true
}

1 Comment

This behaviour does not happen in Webstorm by the way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.