Javascript 等待调试器断开连接... - VSCode 中的 Node.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47701801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Waiting for debugger to disconnect... - Node.js in VSCode
提问by csforbes
I'm trying to step through a simple javascript example in Visual Studio Code, but the debugger hangs trying to disconnect.
我正在尝试在 Visual Studio Code 中逐步执行一个简单的 javascript 示例,但调试器在尝试断开连接时挂起。
macOS Sierra version 10.12.6
macOS Sierra 版本 10.12.6
VSCode version 1.18.1 (up to date)
VSCode 版本 1.18.1(最新)
Node.js v8.9.2 (up to date) installed with Homebrew
与 Homebrew 一起安装的 Node.js v8.9.2(最新)
Debugging with inspector protocol because Node.js v8.9.2 was detected.
node --inspect-brk= /*(port)*/ jsSandbox.js
Debugger listening on ws:// (ip address)
Debugger attached.
Waiting for the debugger to disconnect...
This seems like it's been a closed issue with both Codeand Nodealready, which is why I'm so confused. Am I doing something wrong?
这似乎已经是Code和Node 的一个封闭问题,这就是我如此困惑的原因。难道我做错了什么?
Here is the only javascript file I'm trying to debug:
这是我正在尝试调试的唯一 javascript 文件:
// learning about closure
function increase() { // — gets called once
var getBig = 0;
return function() { // — — gets called each time
getBig += 1; // — — increments each time
console.log(getBig);
};
}
var bigOne = increase(); // -- a reference to the instance of the function
bigOne(); //1
bigOne();//2
...and the project's launch.json config:
...以及项目的 launch.json 配置:
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/jsSandbox.js",
"console": "internalConsole"
}
回答by Nayan Patel
click on the button as shown below to open launch.json-
点击下图按钮打开launch.json-
Give your correct file name here, where your server is starting. In my case it is app.js
在此处输入正确的文件名,即您的服务器启动的位置。就我而言,它是 app.js
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js"
}
]
回答by Mojo
I found a syntax error in my code. The problem was that I wasn't catching the exception. Using VS Code, I just ticked "Uncaught Exceptions" and found the faulty code.
我在我的代码中发现了一个语法错误。问题是我没有捕捉到异常。使用 VS Code,我只是勾选了“未捕获的异常”并找到了错误的代码。
回答by devxbot
I found multiple "Node Debug" extensions installed. "React Native Tools" had a dependency on both of these. After I removed the "React Native Tools" and then the "Node Debug" extensions, VS Code resumed normal and expected behavior of running the debugger. I used the default launch configuration:
我发现安装了多个“节点调试”扩展。“React Native Tools”依赖于这两者。在我删除“React Native Tools”和“Node Debug”扩展之后,VS Code 恢复了运行调试器的正常和预期行为。我使用了默认的启动配置:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/www"
}
]
}
回答by Christèle Legeard
It happens when you break your code. Start your project and you'll see that your app is crashing. Fix the problem and you'll be able to debug again.
当您破坏代码时会发生这种情况。启动你的项目,你会看到你的应用程序崩溃了。修复问题,您将能够再次调试。
回答by A. JELLALI
Use $'{file} for active window:
使用 $'{file} 作为活动窗口:
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Active window",
"program": "${file}"
}]
}
回答by u12218744
you may check .json { "type": "node", "request": "launch", "name": "启动程序", "program": "${workspaceFolder}/main.js" }
你可以检查 .json { "type": "node", "request": "launch", "name": "程序", "program": "${workspaceFolder}/ main.js" }
回答by Rain Wu
Please check your code firstly, there should be some issues when it compiles your code.
请先检查您的代码,编译您的代码时应该会出现一些问题。
回答by Ari
You should make sure the tab showing problemsis empty, i.e., you should address all problems. In cases where the problems are from the files in node_modules, the problems go away just by closing those windows.
您应该确保显示的选项卡problems是空的,即您应该解决所有问题。如果问题来自 中的文件node_modules,只需关闭这些窗口,问题就会消失。
For example in the following pictures, there are 4 issues in Problemstab. Fixing them will make the debugger to work correctly!
例如在下图中,Problems选项卡中有 4 个问题。修复它们将使调试器正常工作!
回答by Rafael Emshoff
For me a dependency crashedwhile debugging, which seems to also crash the vscode debugger itself. Restarting VSCode would allow me to debug again. Removing the faulty dependency (i.e. fixing the code, as suggested in the other answer), allows the debugging process to close, although the Debug Console message still was confusing:
对我来说,调试时依赖项崩溃了,这似乎也会使 vscode 调试器本身崩溃。重新启动 VSCode 将允许我再次调试。删除错误的依赖项(即修复代码,如另一个答案中所建议的那样),允许调试过程关闭,尽管调试控制台消息仍然令人困惑:
Debugger listening on ws://127.0.0.1:48673/54esaf46-659e-sd92-5e45-01e78845825e
Debugger attached.
Waiting for the debugger to disconnect...
It would appear the debugger can't disconnect. But I have no trouble starting a new debug session afterwards.
看起来调试器无法断开连接。但是我之后开始新的调试会话没有问题。
回答by Nilesh Bhujbal
Check your launch.json file. Its present in folder .vscode in your project. In launch.json change program value to ${workspaceFolder}/.
检查您的 launch.json 文件。它存在于项目中的文件夹 .vscode 中。在 launch.json 中,将程序值更改为 ${workspaceFolder}/。


