Search code examples
javascriptnode.jsvisual-studio-codeelectronforge

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. I installed electron-forge package with all dependencies and init my project.

I followed this instruction and my launch.json for VSCode was:

{
    "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.

Then according to this I changed "runtimeExecutable" and my launch.json was as follows:

{
    "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.

Next, I added one line to my 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

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).


Solution

  • I believe that you need to add "protocol"="legacy" To your launch config. This is with the assumption that you are using a Node version < 8.x