How to debug an NPM library package in VSCode?

Viewed 2539

I have made a library in Typescript and will be using it in other NodeJS projects. I have included the source code in the NPM package, so when I install it in my projects where I consume this package, I get the source as well in the node_modules folder.

Now, while debugging my project, I want to be able to hit the breakpoints set in the library code inside node_modules. How can I do this?

Suppose I have my project that I am trying to debug at root/my-project and this project is using an NPM package named @my-org/common which is located at root/my-org-common. Since this library is installed in my-project using NPM, the code for @my-org/common is also included in node_modules at root/my-project/node_modules. How do I set up my VSCode so that breakpoints inside code at root/my-project/node_modules are hit?

1 Answers

Found a solution here: vscode debug code in node_modules directory

Basically, you have to create a symlink which points to the code of the library and then instruct VSCode to use this symlink by putting this in launch.json:

{
    "runtimeArgs": [
        "--preserve-symlinks"
    ]
}
Related