4

I am having a problem setting breakpoints in my TypeScript nodejs app in Visual Studio Code. I have followed the instructions on the Visual Studio Code site without success.

Here is my tasks.json:

{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "showOutput": "always",
    "args": ["-p", "src"],
    "problemMatcher": "$tsc"
}

and here is my tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "node_modules"
    ]
}

It appears as if the source maps are being generated; however attempting to put a breakpoint in any TypeScript file results in a grey circle...what gives? What am I missing?

2 Answers 2

2

You also need to tell VSCode to use sourceMaps, in your launch.json file (which should be located under .vscode/launch.json), you should have something like:

    "configurations": [
    {
        "name": "Launch",
        "type": "node",
        "request": "launch",
        "program": "path/to/your/main.ts",
        "stopOnEntry": false,
        "args": [],
        "cwd": ".",
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development"
        },
        "externalConsole": false,
        "sourceMaps": true
    },

Hope this helps.

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

Comments

2

You need to provide the source maps for VS Code to pinpoint the line of TypeScript code that corresponds to the JavaScript code. The source maps can be automatically generated by the TypeScript compiler, if you set sourceMap to true in tsconfig.json.

You can try this starter code on GitHub, which is built exactly for the purpose of setting breakpoints in VS Code.

Comments

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.