I have a node_js project that includes some of our own node_js packages. They are in an npm private repo and show up in node_modules as:
@company/package_name
We are trying to set breakpoints in this code and find they are never hit.
We thought there might be a default skipFile that excludes node_modules and added to our launch.json:
"skipFiles": ["!${workspaceRoot}/node_modules/**/*.js"]
to no effect.
Any tips on how to enable debugging in the node_modules directory?
I know it's an old question but if someone still manages to stumble upon this, you can use VS code to debug node_module files by first symlinking the node_module package with the main project and then telling VS code to use the symlink.
If you are going to be working in a node_module package, it's a good idea to symlink it so that the changes that you make from within your projects are simultaneously applied to the module's code as well and hence, when you are done editing the package, you can directly see the diff and commit it and instead of copy-pasting it from inside node_module and applying it manually.
npm link
inside the directory.npm link package_name
to link it.For example, if you wanted to link a package sample-node-module with a project sample-project, which uses sample-node-module as its dependency, you can do it in the following manner:
cd sample-node-module
npm link
cd sample-project
npm link sample-node-module
Be careful that you enter the folder name (and not the package name itself) of the cloned repo in the second link
command. You don't have to provide the full path. You can read more about it here
Once you are done with above, you can simply add this small config in your launch.json of VS Code to make it detect breakpoints inside node_modules:
{
"runtimeArgs": [
"--preserve-symlinks"
]
}
Documentation about this can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With