kemakino
kemakino

Reputation: 1122

How to enable debugging of Electron Main and Renderer with VSCode when I use npm-run-all?

I use npm-run-all to run npm start and npm electron . and would like to enable debugging with VSCode, but not sure how to write the launch settings.

Currently, I have the settings below but get only
C:\Program Files\nodejs\npm.cmd dev --inspect-brk=32367
when I start the debugging.

How can I attach the debugger to the electron process?

package.json

{
  ...
  "homepage" : "./",
  "main": "src/main.js",
  ...
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "electron": "electron .",
    "dev": "npm-run-all --parallel electron start"
  },
  ...
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "env": {
                "NODE_ENV": "development"
            },
            "windows": {
                "runtimeExecutable": "npm"
            },
            "runtimeArgs": [
                "dev"
            ]
        }
    ]
}

Upvotes: 1

Views: 2375

Answers (1)

kemakino
kemakino

Reputation: 1122

I didn't add chrome debugger extension for VSCode.
It's now working with this settings, with run-script args.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "dev"
            ],
            "port": 9229
        },
    ]
}

Upvotes: 1

Related Questions