如何在使用`npm run dev`启动的VS Code中调试npm Electron app?

时间:2018-02-04 03:31:37

标签: node.js visual-studio-code electron

在命令行中输入应用程序时没有任何问题我输入npm run dev

现在我正在尝试在Visual Studio Code中创建启动配置,以便我可以调试应用程序。到目前为止,我有:

{
    "type": "node",
    "request": "launch",
    "name": "Launch via NPM",
    "runtimeExecutable": "npm",
    "runtimeArgs": [
        "run",
        "dev"
    ],
    "port": 9229,
    "protocol": "legacy"
}

应用程序可以快速启动,但需要关闭。这似乎与我的Node.js版本(v8.9.1)有关。我收到错误:

Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode.

我尝试使用"protocol": "inspector"但在这种情况下应用程序甚至没有启动,我收到错误:

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9229).

我真的很感谢你提供任何帮助。

1 个答案:

答案 0 :(得分:0)

您可以从“切换开发人员工具”进行子进程调试。

但是对于主要流程,我使用它:

{
 "version": "0.2.0",
 "configurations": [
    {
      "name": "Debug Main Process",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
      "windows": {
         "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
     },
      "args" : ["."]
    }
 ]
}