最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to debug an NPM library package in VSCode? - Stack Overflow

programmeradmin3浏览0评论

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?

Share Improve this question edited May 19, 2021 at 12:28 Ahmad Habib 2,4103 gold badges16 silver badges33 bronze badges asked May 19, 2021 at 12:22 Very Professional UsernameVery Professional Username 1,9153 gold badges22 silver badges35 bronze badges 3
  • If you want to debug the library, maybe just temporarily adjust the main property in package.json to point to src (or equivalent) instead of dist/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
Add a ment  | 

1 Answer 1

Reset to default 4

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"
    ]
}
发布评论

评论列表(0)

  1. 暂无评论