29

What is the difference between args and runtimeArgs in launch.json?

// Optional arguments passed to the runtime executable
"runtimeArgs": []
// Command line arguments passed to the program
"args": []

Is the program not the same thing as the runtime executable?

Extra information and motivation behind the question:

I am developing a nodejs application. In my package.json, I have a start script:

"start": "electron ./src/Main/main.js arg2", and in my app code, I access process.argv[2] which gets me arg2, so when I run npm start, my app works as intended.

When I run the app from VSCode, however it doesn't, and the reason was that I wasn't supplying any additional arguments in launch.json. Where should I put those arguments? process.argv seems to contains the arguments provided in either args or runtimeArgs though it also sticks in some --debug-brk argument, which I don't want.

I want to be able to use process.argv consistently when I run the app from the command line (npm start) or start it from VSCode.

2 Answers 2

20

I think this is mostly explained in the Node debugging docs:

Instead of launching the Node.js program directly with node, you can use 'npm' scripts or other task runner tools directly from a launch configuration:

  • Any program available on the PATH (for example 'npm', 'mocha', 'gulp', etc.) can be used for the runtimeExecutable attribute [...]

runtimeExecutable is not the program you want to debug, but the executable used to run it. So it appears that runtimeArgs is to runtimeExecutable as args is to program.

If you're interested in how it works in detail, here's the relevant part of the debugAdapter.ts implementation.

1
  • I can't see any difference whether I put the "x" argument in "runtimeArgs": ["run-script", "start", "x" ] or in "args": [ "x" ], it leads to the same result: node run-script start x. So, what makes the difference then?
    – Serg
    Mar 22, 2019 at 20:00
6

If you remove the attribute "program", the arguments are attached after another and you don't see any difference.

Consider following example, including "type" and "program":

         {
            
           "name": "vscode-jest-tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest.js",
            "stopOnEntry": false,
            "args": [ 
                "--runInBand"                       
            ],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": null,
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        }

=> set "NODE_ENV=development" && "C:\Program Files\nodejs\node.exe" --nolazy --inspect-brk=35238 node_modules\jest-cli\bin\jest.js --runInBand

  • The runtimeArg "--nolazy" occurs behind node.exe (corresponds to type) and

  • The arg "--runInBand" occurs behind jest.js (corresonds to program)

If you remove the attribute "program", the arguments are attached after another and you don't see any difference.

1
  • for me vscode debugging crash on debug start after adding flag "--experimental-worker" in npm script and forgot to add to lunch.json node config -- adding this to runtimeArgs array fix it.
    – Samih A
    Aug 28, 2020 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.