VS Code调试端口不匹配

时间:2017-08-04 08:49:03

标签: node.js windows debugging visual-studio-code

详细

在Win10中。 VS Code,Help,About ...

  

[窗口标题]
  Visual Studio代码
  
  [内容]
  版本1.14.2
  提交cb82febafda0c8c199b9201ad274e25d9a76874e
  日期2017-07-19T23:34:09.706Z
  壳牌1.6.6
  渲染器56.0.2924.87
  节点7.4.0

生成的launch.json,已根据我的runtime...设置调整

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm.cmd",
            "runtimeArgs": [
                "run", "functional-test"
            ],
            "skipFiles": [
                "<node_internals>/**/*.js"
            ]
        }
    ]
}

上面引用的Npm脚本......

"functional-test": "node test/functional/run-foo-tests",

首次尝试

然后我启动一个调试会话(F5),然后在调试控制台中生成...

  

使用检查器协议进行调试,因为已设置运行时可执行文件   npm.cmd --inspect = 32825 --debug-brk运行功能测试

请注意我的package.json或launch.json中未指定的其他标志。

除上述消息外,我在IDE中显示一个引用连接超时错误的弹出窗口...

  

无法连接到运行时进程,10000毫秒后超时 - (原因:   无法连接到目标:连接ECONNREFUSED

第二次尝试

如果我更改npm脚本如下(包括--inspect标志)...

"functional-test": "node --inspect test/functional/run-foo-tests",

调试控制台声明......

  

使用检查器协议进行调试,因为已设置运行时可执行文件   npm.cmd --inspect = 17976 --debug-brk运行功能测试
  调试器侦听端口9229.
  警告:这是一项实验性功能,可能随时更改。

请注意不同的端口设置。至少调试器正在启动,并给我一个端口来尝试定位。

获得这些价值的地方在哪里?如何使它们匹配(无需手动编辑launch.json和npm脚本为两者分配相同的端口)?

它从未成功加载,而是在顶部显示弹出消息(如上所述。)

第三次尝试

如果我编辑npm脚本以添加端口...

"functional-test": "node --inspect=9229 test/functional/run-foo-tests",

并编辑launch.json的port设置以匹配...

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "npm.cmd",
        "runtimeArgs": [
            "run", "functional-test"
        ],
        "port": 9229,
        "skipFiles": [
            "<node_internals>/**/*.js"
        ]
    }
]

然后我在调试控制台中获得以下消息...

  

使用检查器协议进行调试,因为已设置运行时可执行文件   npm.cmd运行功能测试
  调试器侦听端口5858.
  警告:这是一项实验性功能,可能随时更改   {预期的控制台输出......}

然后它将正常工作(AFAIK!)请注意,现在调试控制台的第二行(回显/记录运行的命令)现在与launch.json runtimeArgs设置匹配(它在第一行中没有)和第二次尝试。)

除了骷髅粉碎的反复试验之外,人们怎么会想到这一点(当然必须有更好的方法?)

第四次尝试

尝试为npm脚本调用设置端口(显然与npm脚本中的node ...调用不同)和port配置参数,并且它在第一个示例中失败。

"runtimeArgs": [
    "run", "functional-test", "--inspect=5858"
],
"port": 5858,

第五次尝试

当然,在我写这篇文章的时候,我终于找到了像an answer via google ......

这样的东西
"scripts": {
    "debug": "node --nolazy --debug-brk=5858 myProgram.js"
},

调整我的脚本以匹配产量(在调试控制台中)......

  

使用检查器协议进行调试,因为运行时可执行文件是   设置。
npm.cmd运行功能测试
(节点:12420)   DeprecationWarning:node -debug已弃用。请使用节点    - 而不是检查。
调试器监听127.0.0.1:5858

我也在顶部显示了一个不同的弹出窗口......

  

无法连接到运行时进程,10000毫秒后超时 - (原因:   无法连接到目标:Parse Error)。

第六次尝试

如果我更改我的脚本以匹配调试控制台中的信息...

"functional-test": "node --nolazy --inspect test/functional/run-foo-tests",

调试控制台说...

  

使用检查器协议进行调试,因为已设置运行时可执行文件   npm.cmd运行功能测试
  调试器侦听端口9229.
  警告:这是一项实验性功能,可能随时更改。

弹出窗口是......

  

无法连接到运行时进程,10000毫秒后超时 - (原因:   无法连接到目标:连接ECONNREFUSED 127.0.0.1

0 个答案:

没有答案
相关问题