Debugging electron-api-demo using Visual Studio Code


#1

After downloading the source from https://github.com/electron/electron-api-demos , I’m able to launch and run the application perfectly. But, If I start debugging the same using VS Code, I get the following error in function makeSingleInstance:

Anything that I’m missing?

Also while debugging, I noticed that my app variable remains undefined till this function call.


#2

Hello All,
After a little bit of fiddling with VSC settings, I was able to do it. Capturing the same here for benefit of those who might run into a similar issue.
Configuration: OSX, Sierra, VS Code 1.10.2, Electron v 1.6.2, node v 6.10.0

  1. Modify the launch.json file (generated by Code, by default, once we click the Debug’s setting button) as following:

{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": “0.2.0”,
“configurations”: [
/*{
“type”: “node”,
“request”: “launch”,
“name”: “Launch Program”,
“program”: “{workspaceRoot}/main.js" }, { "type": "node", "request": "attach", "name": "Attach to Process", "address": "localhost", "port": 5858 }*/ { "name": "Launch Electron", "type": "node", "request": "launch", "program": "{workspaceRoot}/main.js”,
“stopOnEntry”: false,
“args”: ["."],
“cwd”: “{workspaceRoot}", "runtimeExecutable": "{workspaceRoot}/node_modules/electron/dist/electron.app/Contents/MacOS/Electron”,
“env”: { },
“sourceMaps”: false
}
]
}


Guess, the runtimeExecutable could point to either electron or electron-prebuilt (I didn’t try the later one though)
Once the launch.json file is saved, you can see the debug configuration in the top left window of debugger setting selection. Hit Green Button for debugger and you should be able to debug through the electron application with ease.

As shown above, i was able to see valid values for app and BrowserWindow (which were undefined before).

The same process could work for Windows as well. There are some other links to check out as well. Collating them here for reference:

http://mylifeforthecode.com/getting-started-with-electron-in-visual-studio-code/
http://floatincode.net/post/debugging-electron-application-with-visual-studio-code

Hope it helps someone stuck with the same problem that I had. Spent a day figuring out this! :slight_smile: