How to debug using npm run scripts from VSCode?

后端 未结 7 1052
小鲜肉
小鲜肉 2020-12-12 23:55

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

7条回答
  •  [愿得一人]
    2020-12-13 00:22

    It is feasible with npm whithout having to alter your scripts section in package.json

    The trick here is to pass the --inspect-brk=9229 to node.

    The command will look like npm run start -- --inspect-brk=9229

    Here's the .vscode/launch.json:

    {  
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeExecutable": "${env:NVM_BIN}/npm", //change this to your npm path
            "runtimeArgs": [
                "run-script",
                "start",
                "--",
                "--inspect-brk=9229"
            ],
             "port": 9229
        },
    
      ]
    }
    

提交回复
热议问题