javascript - 使用 VSCode 调试 electron-forge 应用程序

标签 javascript node.js visual-studio-code electron forge

我正在尝试使用 VSCode( Electron 主进程,而不是渲染)调试我的 electron-forge 项目,但到处都是错误。我安装了electron-forge打包所有依赖项并初始化我的项目。

我关注了this指导和我的launch.json对于 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}"
        }
    ]
}

但是当我点击 F5在 VSCode 中进行调试,我得到了 Attribute "runtimeExecutable" does not exist因为electron-forge已全局安装,因此 node_modules/.bin/ 中没有此类文件目录。

然后根据this我改了"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

但仍然没有任何反应。我的 Electron 应用程序启动但没有停止为 --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)"="旧版" 到您的启动配置。这是假设您使用的是 Node 版本 < 8.x

关于javascript - 使用 VSCode 调试 electron-forge 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44967814/

相关文章:

javascript - 随机淡入和淡出屏幕上的 x 元素

javascript - Reactjs 中的嵌套循环返回简单的 ListItem - -Object.values 和 Object.keys

javascript - 如何在Compound.JS中自动加载Moment.JS?

node.js - s3 云端应用代码 : NoSuchKey on refreshing

visual-studio-code - VS Code 远程 ssh : how to allow processes to keep running to completion after disconnect?

javascript - 从 html 弹出窗口中删除 null

javascript - 为什么在应用 footable 样式之前显示未样式表一秒钟?

git - npm install,缺少node_modules文件夹

git - 如何使用 GUI 比较两个不同提交中的文件

java - 在 Visual Studio Code IDE 和 OS X 中调试/运行标准 java?