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

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

问题描述

我以前使用 gulp 并运行 gulp 从 Visual Studio Code 调试器启动我的应用程序和侦听器 但最近需要切换到通过 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.

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

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 pm"不存在

Error request 'launch': program 'c:myproject pm' does not exist

相关资源:

推荐答案

看来 VS Code 将支持 2016 年 10 月发布.

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

以下是一个示例,因为它是 在 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 run 脚本进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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