VSCode 调试器不会通过 NPM 与 Launch 连接 [英] VSCode debugger wont attach with Launch via NPM

查看:24
本文介绍了VSCode 调试器不会通过 NPM 与 Launch 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这非常简单,但我似乎无法通过 NPM vscode 模板使调试器与 Launch 一起运行.我有一个非常简单的 hello world 和一个 npm 脚本来运行应用程序.

Im sure this is super simple but I cant seem to get the debugger going with the Launch via NPM vscode template. I have a really simple hello world with an npm script to run the app.

如果我运行 Launch Program(仅使用节点的配置)一切正常,但是如果我使用 Launch via NPM 我得到

If I run Launch Program (the config that uses just node) everything works perfectly, however if I use Launch via NPM I get

/Users/luke/.nvm/versions/node/v6.5.0/bin/npm --debug-brk=3837 run-script runit

/Users/luke/.nvm/versions/node/v6.5.0/bin/npm --debug-brk=3837 run-script runit

hello-world@1.0.0 runit/Users/luke/source/playground/js/hello-world

hello-world@1.0.0 runit /Users/luke/source/playground/js/hello-world

节点 index.js

node index.js

你好世界

并且没有断点被击中.(我也试过有和没有 protocol":legacy")

And no breakpoints are hit. (Ive also tried with and without "protocol":"legacy")

我做错了什么,所有在线示例都表明这应该是可行的.

package.json

package.json

{
  "name": "hello-world",
  "version": "1.0.0",
  "scripts": {
    "runit": "node index.js"
  }
}

launch.json:

launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "protocol":"legacy",
        "runtimeArgs": [
            "run-script",
            "runit"
        ]
    },
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}/index.js"
    }
  ]
}

index.js

console.log('hello world');//with a breakpoint set here

推荐答案

好的,我解决了...

通过 NPM 启动需要您在实际的 NPM 脚本中添加一些额外的参数:

Launch via NPM requires you to add some extra args into the actual NPM script:

{
  "name": "hello-world",
  "version": "1.0.0",
  "scripts": {
    "runit": "node --nolazy --debug-brk=5858 index.js"
  }
}

这篇关于VSCode 调试器不会通过 NPM 与 Launch 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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