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/mon
which is located at root/my-org-mon
. Since this library is installed in my-project
using NPM, the code for @my-org/mon
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?
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/mon
which is located at root/my-org-mon
. Since this library is installed in my-project
using NPM, the code for @my-org/mon
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?
-
If you want to debug the library, maybe just temporarily adjust the
main
property in package.json to point tosrc
(or equivalent) instead ofdist
/build
? – Siddharth Commented May 19, 2021 at 12:41 -
The project code I am talking about is an ExpressJS project which has routers and controllers and the library code has just data models, utils and service methods. I want to debug the library methods which are called through the service. Will changing the
main
in package.json work in this case? – Very Professional Username Commented May 19, 2021 at 12:54 - Unfortunately there are no tests for the library code or I would have debugged it using those tests. – Very Professional Username Commented May 19, 2021 at 12:55
1 Answer
Reset to default 4Found 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"
]
}