[英]Debug electron-forge app with VSCode
I'm trying to debug my electron-forge project with VSCode (electron main process, not render) but getting erros everywhere. 我正在尝试使用VSCode调试我的电子锻造项目(电子主过程,而不是渲染),但到处都是错误的。 I installed
electron-forge
package with all dependencies and init my project. 我安装了包含所有依赖项的
electron-forge
包并初始化我的项目。
I followed this instruction and my launch.json
for VSCode was: 我遵循了这条指令,我的
launch.json
for 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}"
}
]
}
But when I hit F5
in VSCode to debug, I got Attribute "runtimeExecutable" does not exist
because electron-forge
is installed globally so there is no such file in node_modules/.bin/
dir. 但是当我在VSCode中按
F5
进行调试时,我得到的Attribute "runtimeExecutable" does not exist
因为electron-forge
Attribute "runtimeExecutable" does not exist
是全局安装的,因此node_modules/.bin/
dir中没有这样的文件。
Then according to this I changed "runtimeExecutable"
and my launch.json
was as follows: 然后根据这个我更改了
"runtimeExecutable"
,我的launch.json
如下:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "electron-forge-vscode-win.cmd",
"cwd": "${workspaceRoot}"
}
]
}
The comand line was: 命令行是:
electron-forge-vscode-win.cmd --debug-brk=17423 --nolazy
√ Locating Application
√ Preparing native dependencies
√ Launching Application
But still nothig happened. 但仍然没有发生。 My electron app started but didn't stop as
--debug-brk
argument supposed. 我的电子应用程序启动但并没有因为
--debug-brk
论证而停止。
Next, I added one line to my launch.json
: 接下来,我在
launch.json
添加了一行:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"name": "Electron Main",
"runtimeExecutable": "electron-forge-vscode-win.cmd",
"protocol": "inspector"
}
]
}
Launched with this command line: 使用此命令行启动:
electron-forge-vscode-win.cmd --inspect=11172 --debug-brk
√ Locating Application
√ Preparing native dependencies
√ Launching Application
Note: 11172 is a random port number 注意: 11172 是随机端口号
And now I'm getting this error: Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:11172)
. 现在我收到此错误:
Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:11172)
。
I believe that you need to add "protocol"="legacy"
To your launch config. 我相信你需要在你的启动配置中添加
"protocol"="legacy"
。 This is with the assumption that you are using a Node version < 8.x 这假设您使用的是Node版本<8.x.
I've come to the conclusion that you cannot use VSCode to debug the main electron process if you use electron-forge or electron-compile. 我得出的结论是,如果使用电子伪造或电子编译,就不能使用VSCode来调试主电子过程。 In both cases, the VSCode debugger ignores breakpoints.
在这两种情况下,VSCode调试器都会忽略断点。 The BrowserWindow comes up directly and the following message appears in the VSCode debug console window:
BrowserWindow直接出现,VSCode调试控制台窗口中显示以下消息:
Debugging with inspector protocol because a runtime executable is set.
c:\Users\paulk\OneDrive\dev\forge-debug/node_modules/.bin/electron.CMD --inspect=16988 --debug-brk .
Debugger listening on ws://127.0.0.1:16988/9cead160-c448-4b33-a8a2-2dff6f51ed59
Sometimes when I close the browser window, a breakpoint in the "close all windows" event handler is hit. 有时当我关闭浏览器窗口时,会触发“关闭所有窗口”事件处理程序中的断点。 After closing the window, the following message appears in the debug console:
关闭窗口后,调试控制台中将显示以下消息:
Debugger attached.
Perhaps this indicates that the VSCode debugger does not attach until after the BrowserWindow closes. 也许这表明VSCode调试器在BrowserWindow关闭之后才会附加。
I believe the problem originates with electron-compile, which eletron-forge uses. 我认为问题源于电子编译,eletron-forge使用。 Perhaps it has something to do with compiling on the fly.
也许它与动态编译有关。
Use VSCode to debug a simple Electron app is a breeze. 使用VSCode调试简单的Electron应用程序是一件轻而易举的事。 Further, plain Electron emits a different message in the debugger window:
此外,plain Electron在调试器窗口中发出不同的消息:
Debugging with inspector protocol because a runtime executable is set.
c:\Users\paulk\OneDrive\dev\electron-quick-start/node_modules/.bin/electron.CMD --inspect=37884 --debug-brk .
Debugger listening on port 37884.
Warning: This is an experimental feature and could change at any time.
This indicates that plain Electron is using a different method of connecting to the debugger than does electron-compile. 这表明普通电子使用与电子编译不同的连接调试器的方法。
It is a shame that electron-forge does not work with VSCode main process debugging. 令人遗憾的是,电子伪造不适用于VSCode主进程调试。 This makes it useless for me.
这对我来说没用。 Also, the developers of electron-forge and electron-compile do not seem to consider this a problem.
此外,电子伪造和电子编译的开发人员似乎并不认为这是一个问题。 It would be helpful to know what debuggers the developers of electron-forge and electron-compile and the users of these packages are using to debug main process code.
了解电子伪造和电子编译的开发人员以及这些软件包的用户正在使用哪些调试器来调试主进程代码将会很有帮助。
Just add 【"port": 11172】
in launch.json
after protocol. 只需在
launch.json
之后添加【"port": 11172】
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.