Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug npm modules?

Normally you yarn/npm install react, then use it with import React from 'react'

Say you want to debug a React source and you clone a GitHub repo.

How do you use the source in your project instead of the lib version?

  • edit

To further develop philipheinser's answer, here's what I encountered with doing npm link draft-js-mention-plugin

npm link seems to run npm run build which is the scripts command in the package.json that you want to link.

with draft-js-mention-plugin, npm run build runs ../node_modules/.bin/rimraf lib and I had to go up a directory and run npm install to install the rimraf

draft-js-mention-plugin has parent draft-js-plugins and it has its own package.json

like image 543
eugene Avatar asked Mar 26 '20 10:03

eugene


People also ask

How do you debug node modules in VS code?

There are a few ways you can debug your Node.js programs in VS Code: Use auto attach to debug processes you run in VS Code's integrated terminal. Use the JavaScript debug terminal, similar to using the integrated terminal. Use a launch config to start your program, or attach to a process launched outside of VS Code.

What is debug npm?

debug exposes a function; simply pass this function the name of your module, and it will return a decorated version of console. error for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.


2 Answers

You can use npm link your version of the code: https://docs.npmjs.com/cli/link.html

like image 118
philipheinser Avatar answered Oct 14 '22 19:10

philipheinser


If you want to mimic a more production like situation you might use this workflow:

Create a package of your submodule locally:

cd /path/to/your/module
npm pack

This will create a .tgz file of your package in /path/to/your/module

Install the local package of the submodule in your application:

cd /path/to/your/application    
npm install /path/to/your/module/<YourModule>-<YourModulesVersion>.tgz

This will install the .tgz file in your application's node_modules directory

These steps should be repeated after adjustments to your module.

like image 27
Tom Ritsema Avatar answered Oct 14 '22 20:10

Tom Ritsema