簡體   English   中英

使用VSCode調試電子鍛造應用程序

[英]Debug electron-forge app with VSCode

我正在嘗試使用VSCode調試我的電子鍛造項目(電子主過程,而不是渲染),但到處都是錯誤的。 我安裝了包含所有依賴項的electron-forge包並初始化我的項目。

我遵循了條指令,我的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}"
        }
    ]
}

但是當我在VSCode中按F5進行調試時,我得到的Attribute "runtimeExecutable" does not exist因為electron-forge Attribute "runtimeExecutable" does not exist是全局安裝的,因此node_modules/.bin/ dir中沒有這樣的文件。

然后根據這個我更改了"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

但仍然沒有發生。 我的電子應用程序啟動但並沒有因為--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"="legacy" 這假設您使用的是Node版本<8.x.

我得出的結論是,如果使用電子偽造或電子編譯,就不能使用VSCode來調試主電子過程。 在這兩種情況下,VSCode調試器都會忽略斷點。 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

有時當我關閉瀏覽器窗口時,會觸發“關閉所有窗口”事件處理程序中的斷點。 關閉窗口后,調試控制台中將顯示以下消息:

Debugger attached.

也許這表明VSCode調試器在BrowserWindow關閉之后才會附加。

我認為問題源於電子編譯,eletron-forge使用。 也許它與動態編譯有關。

使用VSCode調試簡單的Electron應用程序是一件輕而易舉的事。 此外,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.

這表明普通電子使用與電子編譯不同的連接調試器的方法。

令人遺憾的是,電子偽造不適用於VSCode主進程調試。 這對我來說沒用。 此外,電子偽造和電子編譯的開發人員似乎並不認為這是一個問題。 了解電子偽造和電子編譯的開發人員以及這些軟件包的用戶正在使用哪些調試器來調試主進程代碼將會很有幫助。

只需在launch.json之后添加【"port": 11172】

我的launch.json文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM