Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log() from node_modules

How do I console.log() from dependencies in node_modules in my node project? I'm using the default create-react-app setup.

When I include console.log() in my application code, logging works fine. However, when I try to include console.log() in the code of one of the project's dependencies in node_modules, these do not appear in my console.

Any way I can get those logs?

like image 339
artooras Avatar asked Dec 10 '18 15:12

artooras


2 Answers

If you are monkey patching an npm module with a console.log() to debug an issue it should show up just like any other console statement would. It's probable that your root cause is your build. I'm making some assumptions that you are using babel and a bundler tool like Webpack.

  • Make sure you are doing a full rebuild of your project
  • clear babel cache or try BABEL_DISABLE_CACHE=1 webpack
  • Double check the console.log you are adding isn't in source code of the dependency therefor is never being called.
  • Try adding a console.log higher up in the file of dependency to better know it's being loaded at all

Alternatively I'd personally recommend you reconsider your approach. While I've actually done this a couple times; if you are adding "debugging" like this to lower level modules you are probably looking in the wrong place for your issue unless there is a legit bug in the lib...

like image 58
Russ Brown Avatar answered Nov 09 '22 02:11

Russ Brown


If you want to debug a dependency you should copy the dependency from node_modules in to your project, and call from yours projects path

like image 43
HDallakyan Avatar answered Nov 09 '22 02:11

HDallakyan