简体   繁体   English

使用VSCode调试电子锻造应用程序

[英]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】

我的launch.json文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 电子锻造制造不会建造 - electron-forge make won't build 电子锻造:如何指定钩子? - electron-forge: how to specify hooks? Electron-forge npm run make“错误:找不到您的应用程序的主要入口点。” - Electron-forge npm run make "Error: The main entry point to your app was not found." “未捕获的 ReferenceError:require is not defined” 在 index.html 的电子锻造应用程序与反应模板 - “Uncaught ReferenceError: require is not defined” in index.html of electron-forge app with react template ElectronJS npm 启动/bash:电子伪造:找不到命令 - ElectronJS npm start / bash: electron-forge: command not found 使用电子伪造打包应用程序时出现问题“无法解析'./→'” - Problem while packaging application with electron-forge “Can't resolve './→' ” @electron-forge/plugin-webpack 中的 configuration.module.rules[2] 问题 - configuration.module.rules[2] Issue in @electron-forge/plugin-webpack 无法在VSCode中调试Electron JS应用程序 - Cannot Debug Electron JS application in VSCode 在电子锻造项目中安装“node-pty”后,缺少名为 pty.node.js 的文件。 如何在 Linux 中安装 node-pty - A file called pty.node.js is missing after installing "node-pty" in a electron-forge project. How can I install node-pty in Linux Electron 用反应锻造? - Electron Forge with react?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM