I have an npm script that I am trying to debug. I am using vscode, so I decided to create a debug configuration and execute it using a debugger.
My npm script number is as follows:
"scripts": { ... "dev": "node tasks/runner.js", }
So, I created the following debug configuration:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "runtimeExecutable": "npm", "cwd": "${workspaceRoot}", "runtimeArgs": [ "run", "dev" ], "port": 5858, "stopOnEntry": true } ] }
And when I run it, the script runs, but vscode can never connect, and I get the error message:
Unable to connect to runtime via the 'legacy' protocol; consider using the inspector protocol (latency after 10,000 ms).
I tried to add an inspector protocol:
{ "type": "node", "request": "attach", "name": "Attach (Inspector Protocol)", "port": 9229, "protocol": "inspector" }
And run npm script with:
npm run dev --inspect
And this time I get an error message:
Make sure Node is running with --inspect. Unable to connect to the execution process, timeout after 10000 ms - (reason: cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9229).
I'm not sure which part I am missing.
Edit for each duplicate tag
I see another question: debugging an npm script via vscode, but the details in other questions and answers are not as detailed and specific. If someone is looking for specific vscode error messages that I stumbled upon, or the type of configuration that I had, they will not necessarily get a detailed answer to the level that this question of your choice gives.