Run NPX commands in debug mode
Asked Answered
M

2

19

I got some npx create-react-app command stuck without showing any error on the terminal. So, I require to run npx in debug mode.

Is there a way to get a debug log for npx commands to identify the issue?


edit: the command I ran:

npx create-react-app my-app
Merriment answered 14/4, 2020 at 15:6 Comment(7)
are you not getting any error on the terminal?Stereoscopic
no. no any errorsMerriment
what's the full command you are running?Stereoscopic
I added it to the questionMerriment
and.... nothing happens at all? can you post a screenshot?Stereoscopic
i.sstatic.net/UJnVn.pngMerriment
does it hang at that spot forever?Stereoscopic
L
13

You can find the answer here. you can debug an npx command providing the --node-options=--inspect command line argument:

npx --node-options=--inspect create-react-app my-app

Then in Chrome and you will find a NodeJs debugger button at the top of the Developer Tools panel:

enter image description here

Click on it and a new Chrome Developer Tools instance will start with your project loaded in the source code.

Search the file you need to debug (either in the tree view or using the quick search Cmd/Ctrl-O feature) and place a breakpoint in the Developer Tools editor.

Then restart the npx command and start troubleshooting the create-react-app module.

Loveinidleness answered 4/2, 2021 at 22:3 Comment(2)
Since npm 7 --node-arg has been replaced by --node-options so you should do: npx --node-options="--inspect" your-script In this case: npx --node-options="--inspect" create-react-app my-appMorrie
And to have the process wait for the debugger to attach and keep it paused before executing the very first statement, leverage node's --inspect-brk; e.g. npx --node-options=--inspect-brk create-react-app my-app.Coxcombry
M
3

I don't know which argument you can pass to npx but you can do it with npm run:

npm -dd run create-react-app my-app

Morrie answered 14/1, 2022 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.