How to start jscodeshift in inspect mode?

797 Views Asked by At

This used to be runnable but recently I'm encounter the following issue.

By running the following command:

node --inspect-brk ./node_modules/.bin/jscodeshift mod.js file.

I am encountering this problem

Debugger listening on ws://127.0.0.1:9229/7e57a2d3-0885-44b3-b51e-b47dc8417d87
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Processing 1 files... 
Spawning 1 workers...
Sending 1 files to free worker...
Starting inspector on 127.0.0.1:9229 failed: address already in use
All done. 
Results: 
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.035seconds 
3

There are 3 best solutions below

2
Patrick Eriksson On

The reason inspect mode doesn't work is because another process (e.g. another instance of the inspector) is already using the default port (9229), so they're conflicting. Either use a different port for the inspector or kill the process that's currently using the port.

If you use a different port, you'll be able to start the inspector. Just pass the desired port-number (e.g. 39479) to --inspect-brk.

Your example: node --inspect-brk ./node_modules/.bin/jscodeshift mod.js file.

Could for example be: node --inspect-brk=39479 ./node_modules/.bin/jscodeshift mod.js file.

DANGER: If you need the port 9229, you can kill the process/inspector that's currently using that port, but if you don't know what that process is doing you could damage things: lsof -i TCP:9229 | grep LISTEN | awk '{print $2}' | xargs kill -9

1
Anupam Rai On

What worked for me:

  1. Start node-inspector
  2. Install jscodeshift in my local repo as a dev dependency.
  3. put debugger statement in my script
  4. run jscodeshift via node with --debug-brk arg and added --run-in-band jscodeshift param. For example :- I entered node

    --debug-brk ./node_modules/jscodeshift/bin/jscodeshift.sh -t my-refactor-script.js --run-in-band

If you add a file pattern at the end, it works fine, which in the case of debugging is helpful when you want to test just one trouble file.

I did not test debugging jscodeshift installed via npm -g

0
user2167582 On

The answer that worked for me was installing ndb, https://github.com/GoogleChromeLabs/ndb, and prefixing the command with it.

ndb node --inspect-brk ./node_modules/.bin/jscodeshift mod.js