如何使用VSCode中的npm运行脚本进行调试? [英] How to debug using npm run scripts from VSCode?

查看:1536
本文介绍了如何使用VSCode中的npm运行脚本进行调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前使用gulp并运行gulp来从 Visual Studio代码调试器启动应用程序和侦听器,但最近需要通过 npm 切换到正在运行的脚本。不幸的是,在VSCode中,我无法通过调试器运行 npm 脚本,因此我不得不依靠运行 node 来直接启动服务器,这摆脱了我的困扰侦听器任务,这些任务会自动重新加载代码。

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.

这看起来应该很简单,但到目前为止我还没有遇到很多运气。下面是我尝试使用的launch.json文件中的一个片段,但找不到 npm

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"
        ],
    ...
}

这给了我以下错误


错误请求启动:程序'c:\myproject\npm'不存在

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

相关资源:

  • https://github.com/Microsoft/vscode/issues/2726

推荐答案

从2016年10月发布

下面是一个示例,因为它是在GitHub上提出

Below is an example as it was proposed on GitHub.

packages.json

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

vscode启动配置

{
    "name": "Launch via NPM",
    "type": "node",
    "request": "launch",
    "cwd": "${workspaceRoot}",
    "runtimeExecutable": "npm",
    "runtimeArgs": [
        "run-script", "debug"
    ],
    "port": 5858
}

这篇关于如何使用VSCode中的npm运行脚本进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆