【发布时间】: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,
}
]
}
我尝试过什么但没有改变:
- 我按照https://github.com/microsoft/vscode/issues/102166#issuecomment-657138385 的建议使用
Use debug.javascript.usePreview: false - 我按照某些帖子的建议添加了
localRoot和remoteRoot。
启动调试器时的输出:
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