Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger and runTimeArgs order #16173

Closed
danielepolencic opened this issue Nov 28, 2016 · 8 comments
Closed

Debugger and runTimeArgs order #16173

danielepolencic opened this issue Nov 28, 2016 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Milestone

Comments

@danielepolencic
Copy link

  • VSCode Version: 1.7.2
  • OS Version: macos 10.12.1

I don't have nodejs installed locally on my machine, but I'm using the official docker image to run the typescript. I tried to setup VS Code to launch the docker image but the --debug-brk flag is injected before any of the arguments. Is there any way I could control the order of the arguments?

Steps to Reproduce:

  1. Use the following launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}/index.ts",
      "cwd": "${workspaceRoot}",
      "outFiles": [],
      "sourceMaps": true,
      "env": {
        "NODE_ENV": "development"
      },
      "outDir": "${workspaceRoot}/bin",
      "runtimeExecutable": "docker",
      "runtimeArgs": ["run", "-ti", "node:6.9.1"]
    }
  ]
}
  1. Run the program in debug mode.

The console prints:

docker --debug-brk=35420 run -ti node:6.9.1 bin/index.js 
flag provided but not defined: --debug-brk
See 'docker --help'.

To run the application in docker that line should read instead:

docker run -ti node:6.9.1 bin/index.js --debug-brk=35420
@chrmarti chrmarti added the debug Debug viewlet, configurations, breakpoints, adapter issues label Nov 29, 2016
@chrmarti chrmarti added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Nov 29, 2016
@weinand
Copy link
Contributor

weinand commented Nov 29, 2016

@danielepolencic you can avoid that VS Code passes a --debug-brk=nnnnn to the runtime by managing the debug port manually. Just set a "port": 55555 attribute in your launch config and add a corresponding runtime argument "--debug-brk=55555".

And please use outFiles correctly instead of the deprecated outDir.

This should work:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}/index.ts",
      "cwd": "${workspaceRoot}",
      "outFiles": [ "${workspaceRoot}/bin/**/*.js" ],
      "sourceMaps": true,
      "env": {
        "NODE_ENV": "development"
      },
      "port": 35420,
      "runtimeExecutable": "docker",
      "runtimeArgs": ["run", "-ti", "node:6.9.1", "--debug-brk=35420" ]
    }
  ]
}

@papandreou
Copy link

@weinand, sorry for commenting on an old issue, but I just ran into a similar problem while trying to get VS Code to collaborate with nvm, and I've come to believe that this issue shouldn't have been closed.

I got it to work using your workaround:

{
  "version": "0.2.0",
  "configurations": [
    {
      "protocol": "inspector",
      "type": "node",
      "request": "launch",
      "name": "Mocha Tests",
      "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
      // Hardwire the port to prevent VS from injecting --inspect-brk=... before the runtimeArgs:
      // https://github.com/Microsoft/vscode/issues/16173#issuecomment-263496120
      "port": 49534,
      "args": [
        "-u", "tdd",
        "--timeout", "999999",
        // ...
        "tests/**/*.js"
      ],
      "internalConsoleOptions": "openOnSessionStart",
      "runtimeExecutable": "${env:NVM_DIR}/nvm-exec",
      "runtimeArgs": [
        "node",
        "--inspect-brk=49534" // Has to match the "port" config above
      ]
    }
  ]
}

It would have been nicer if I could just have omitted the "port": 49534 config and the hardcoded --inspect-brk=49534, but if I do that, a non-functional command line is generated, similar to the Docker problem mentioned above:

/Users/andreaslind/.nvm/nvm-exec --inspect=41943 --debug-brk node node_modules/mocha/bin/_mocha -u tdd --timeout 999999 ... tests/**/*.js 

... the problem being that node (from runtimeArgs) should come right after /Users/andreaslind/.nvm/nvm-exec.

It seems unintuitive that Code would inject that before the runtimeArgs, and now we have two examples of it causing undesirable results. Don't you agree that it seems like an actual bug?

@weinand weinand reopened this Nov 9, 2017
@weinand weinand removed the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Nov 9, 2017
@weinand weinand modified the milestones: November 2016, November 2017 Nov 9, 2017
@weinand weinand added the bug Issue identified by VS Code Team member as probable bug label Nov 9, 2017
@auchenberg
Copy link
Contributor

@papandreou Wouldn't you setting your default Node version via NVM solve things and simplify the configuration? https://eric.blog/2016/08/23/set-default-node-version-with-nvm/

@papandreou
Copy link

Hey @auchenberg, long time no see :). I have specified the default alias, but I’m working on several projects, and they’re not all ready to upgrade node at the same time. I think it’s very common for applications (rather than libs) to be tied to a single major version of node at any given time. Upgrading will usually require you to upgrade several dependencies, some of which won’t be backwards compatible with the old node version. Also, you’ll quickly start to use new language features that weren’t available in the old version.

Because of that, it’s practical to have local .nvmrc files version controlled with the individual projects. For the lack of something better, .nvmrc checked in at the root seems to have become the standard way of declaring the node version, as you can also tell from the number of people weighing in here and here

As another example, Travis supports .nvmrc directly: https://docs.travis-ci.com/user/languages/javascript-with-nodejs/#Specifying-Node.js-versions-using-.nvmrc

weinand added a commit to microsoft/vscode-node-debug that referenced this issue Nov 10, 2017
@weinand
Copy link
Contributor

weinand commented Nov 10, 2017

@roblourens For the legacy protocol I'm now adding the --debug... flag after all runtimeArgs (instead of before). You might want to do the same for the --inspect... flag for the inspector protocol.

@roblourens
Copy link
Member

Done!

@papandreou
Copy link

Wow, thanks, guys :)

@weinand weinand closed this as completed Nov 10, 2017
@weinand weinand added the verification-needed Verification of issue is requested label Dec 4, 2017
@weinand
Copy link
Contributor

weinand commented Dec 5, 2017

Verification:
create a launch config that has both runtime args and program args, then verify that the "--debug" or "--inspect" argument comes at the end of the runtime args before the program args.
You can see the full command line in the debug console.
Verify this for both protocols.

@aeschli aeschli added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Dec 6, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants