【问题标题】:VSC breakpoints remain unboundVSC 断点保持未绑定
【发布时间】:2021-07-12 05:02:12
【问题描述】:

我正在尝试使用 Visual Studio Code 调试器来调试 Node.js 应用程序。但是,所有断点仍然“未绑定”。为什么断点不绑定?

我使用 VSC v1.55.2 和 Node v9.8.0。 我的配置launch.json

{
    "configurations": [
        {
            "name": "Debug Server Side",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "program": "${workspaceFolder}/server.js",
            "request": "launch",
            "restart": true,
            "runtimeExecutable": "nodemon",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node",

            // I added:
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/",
            "trace": true,
        }
    ]
}

我尝试过什么但没有改变:

启动调试器时的输出:

cd "C:\\Users\\Xxx\\Documents\\vsc portal" ; /usr/bin/env '
NODE_OPTIONS=--require C:\Users\Xxx\AppData\Local\Temp\vscode-js-debug-bootlo
ader.js' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"\\\\.\\pipe\\node-cdp.7888-
2.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files
\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallb
ack":"C:\\Users\\Xxx\\AppData\\Local\\Temp\\node-debug-callback-4cee0248d1dfa
f08"}' "C:\\Program Files\\nodejs\\nodemon.cmd" .\\server.js 
Debugger listening on ws://127.0.0.1:55555/88f9181c-b2e1-4fe9-9df1-a20ba0485382
For help see https://nodejs.org/en/docs/inspector
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node .\server.js`
Debugger listening on ws://127.0.0.1:55556/d9fd2280-08b7-4f4a-892d-f6562ec9441f
For help see https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:55561/e504b1f9-67cf-41fc-89f7-cf3127f6850d
For help see https://nodejs.org/en/docs/inspector

详细日志:https://www.dropbox.com/s/x8x6nv9jvevcs74/vscode-debugadapter-b56a956a.json?dl=0

例如,我在server.js 的第 3 行和第 5 行添加了一个断点,它们都是未绑定的:

const app = require("./app");
const { SERVER_PORT } = process.env;
app.set("port", SERVER_PORT);
const server = app.listen(app.get("port"), () => {
    console.log(`Server running → PORT ${server.address().port}`);
});

【问题讨论】:

  • 您检查过插入断点的确切位置吗?似乎 VSC 不喜欢 -callbacks 处的断点,例如 array.map/forEach 等使用的断点。我也看到过异步代码的这种行为,但并非总是如此。
  • @ak_linus,我不认为就是这样,但为了确保我在帖子末尾添加了一个 2 个断点的示例以进行检查。这些断点不应该起作用吗?
  • 我在一个新项目上尝试了相同的设置,一切都按预期工作。我认为您的节​​点配置有问题,在 VS Code 之外。您是否尝试过使用"runtimeExecutable": "node" 而不是nodemon 进行调试
  • 在调试窗口列表中,一般部分下,你可以找到以下选项:'enable the debug JavaScript'之类的,确保它被选中,如果它被选中则问题不在 Visual Studio 调试器中,而是在其他一些配置中。
  • 我也做了你所做的一切。无限的断点错误让我发疯。尝试清理重建整个项目。

标签: node.js visual-studio-code vscode-debugger


【解决方案1】:

我使用的是 Node 版本 9.8.0,更新到 Node 版本 14.15.1 解决了它。

【讨论】:

    【解决方案2】:

    您应该尝试在 VSC 扩展中安装 JavaScript 调试器。然后使用该调试器打开新终端。

    【讨论】:

    • 感谢@deko_39,但是 Javascript 调试器是内置在 VSC 中的,所以它已经安装了。附言安装 Javascript 调试器的夜间版本也不能解决问题。
    • 安装该扩展后。在配置数组中添加这个对象: { "type": "node-terminal", "name": "Create JavaScript Debug Terminal", "request": "launch", "cwd": "${workspaceFolder}" }
    • 或者你可以去调试选项卡,选择 nodejs >> 创建 javascript 调试终端,该对象将自动添加到配置中。希望对您有所帮助。
    猜你喜欢
    • 2021-11-02
    • 1970-01-01
    • 2020-12-06
    • 2020-06-20
    • 2020-10-22
    • 2019-07-18
    • 2021-02-11
    • 2016-06-07
    • 2021-10-15
    相关资源
    最近更新 更多