我无法使用 vscode 在 Windows 上调试 electron 主进程。我已经尝试了我能找到的所有可能的 launch.json
配置,但是 app
对象始终是 undefined
。应用程序有效,我只有调试有问题。看来我的 runtimeExecutable
路径是错误的。我试过了 https://discuss.atom.io/t/debugging-electron-api-demo-using-visual-studio-code/40661/2我从文档中获取了当前配置 https://github.com/electron/electron/blob/master/docs/tutorial/debugging-main-process-vscode.md
我的launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app/main.ts",
"stopOnEntry": false,
"args": ["."],
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"outFiles": [
"${workspaceRoot}/dist/main.js"
],
"env": { },
"sourceMaps": true
}
]
}
最佳答案
根据文档 https://code.visualstudio.com/docs/nodejs/nodejs-debugging Electron 尚不支持 Inspector 协议(protocol)
。
这是工作配置。应该添加协议(protocol)遗留。
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app/main.ts",
"stopOnEntry": false,
"args": ["."],
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"outFiles": [
"${workspaceRoot}/dist/main.js"
],
"protocol":"legacy",
"env": { },
"sourceMaps": true
}
]
}
关于debugging - 使用 vscode 调试 electron。运行时可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45373937/