详情

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

[Window Title] Visual Studio Code [Content] Version 1.14.2 Commit cb82febafda0c8c199b9201ad274e25d9a76874e Date 2017-07-19T23:34:09.706Z Shell 1.6.6 Renderer 56.0.2924.87 Node 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运行功能测试

Note the additional flags that aren't specified anywhere in my package.json or launch.json.

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

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

第二次尝试

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

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

调试控制台说明......

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

注意不同的端口设置 . 至少调试器正在启动并给我一个端口来尝试和目标 .

Where is it getting those values? How can I make them match (without manually editing both launch.json and npm script to assign the same port for both)?

它永远不会成功加载,而是在顶部显示弹出消息(如上所述) .

第三次尝试

如果我编辑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 设置(它在第一次和第二次尝试中没有) .

Aside from skull-smashing brute force of trial and error, how was one supposed to figure this out (and surely there must be a better way?)

第四次尝试

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

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

第五次尝试

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

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

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

使用检查器协议进行调试,因为已设置运行时可执行文件 . npm.cmd运行functional-test(node:12420)DeprecationWarning:node -debug不推荐使用 . 请改用node --inspect . 调试器监听127.0.0.1:5858

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

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

第六次尝试

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

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

调试控制台说......

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

弹出窗口是......

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