Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug using npm run scripts from VSCode?

I was previously using gulp and running gulp to start my application and listeners from the Visual Studio Code debugger but have recently needed to switch to running scripts through npm instead. Unfortunately in VSCode I've not been able to run npm scripts through the debugger so I've had to resort to running node to start my server directly which gets rid of my listener tasks which reloaded code automatically.

This seems like something that should be simple but so far I haven't had much luck. Below is a snippet from my launch.json file that I attempted to use but npm could not be located.

{     ...         "program": "npm",         "args": [             "run",             "debug"         ],     ... } 

This gives me the following error.

Error request 'launch': program 'c:\myproject\npm' does not exist

Related resources:

  • https://github.com/Microsoft/vscode/issues/2726
like image 538
jpierson Avatar asked Jan 17 '16 04:01

jpierson


People also ask

How do you debug a script on VS Code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


1 Answers

It appears that VS Code will support npm scripts and other launch scenarios in the release from October 2016.

Below is an example as it was proposed on GitHub.

packages.json

  "scripts": {     "debug": "node --nolazy --debug-brk=5858 myProgram.js"   }, 

vscode launch config

{     "name": "Launch via NPM",     "type": "node",     "request": "launch",     "cwd": "${workspaceRoot}",     "runtimeExecutable": "npm",     "runtimeArgs": [         "run-script", "debug"     ],     "port": 5858 } 
like image 69
jpierson Avatar answered Sep 21 '22 22:09

jpierson