我正在尝试使用 VSCode( Electron 主进程,而不是渲染)调试我的 electron-forge 项目,但到处都是错误。我安装了electron-forge
打包所有依赖项并初始化我的项目。
我关注了this指导和我的launch.json
对于 VSCode 是:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd",
"cwd": "${workspaceRoot}"
}
]
}
但是当我点击 F5
在 VSCode 中进行调试,我得到了 Attribute "runtimeExecutable" does not exist
因为electron-forge
已全局安装,因此 node_modules/.bin/
中没有此类文件目录。
然后根据this我改了"runtimeExecutable"
和我的 launch.json
如下:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "electron-forge-vscode-win.cmd",
"cwd": "${workspaceRoot}"
}
]
}
命令行是:
electron-forge-vscode-win.cmd --debug-brk=17423 --nolazy
√ Locating Application
√ Preparing native dependencies
√ Launching Application
但仍然没有任何反应。我的 Electron 应用程序启动但没有停止为 --debug-brk
假设的论点。
接下来,我在 launch.json
中添加了一行:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"name": "Electron Main",
"runtimeExecutable": "electron-forge-vscode-win.cmd",
"protocol": "inspector"
}
]
}
使用此命令行启动:
electron-forge-vscode-win.cmd --inspect=11172 --debug-brk
√ Locating Application
√ Preparing native dependencies
√ Launching Application
注意: 11172 是随机端口号
现在我收到这个错误:Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:11172)
.
最佳答案
我相信你需要添加
"协议(protocol)"="旧版"
到您的启动配置。这是假设您使用的是 Node 版本 < 8.x
关于javascript - 使用 VSCode 调试 electron-forge 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44967814/