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

It appears that launch.json does not pass on the PATH variable setting when testing the version of electron #865

Closed
wihd opened this issue Nov 25, 2020 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s)

Comments

@wihd
Copy link

wihd commented Nov 25, 2020

Describe the bug

I am unable to debug an electron application on macOS. Although Node.js is installed, the debug action fails immediately reporting:

Can't find Node.js binary "<omitted>/node_modules/.bin/electron":
error getting version: <omitted>/node_modules/.bin/electron exited with code 127:
env: node: No such file or directory.
Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json

Experimentation suggests that the problem is that although launch.json contains a setting for the PATH environment variable, pointing to node's location, this setting is ignored when trying to determine the version of the electron application.

To reproduce

  1. Launch VS Code on macOS from spotlight or dock.
  2. Attempt to debug an electron application, launched with launch.json:
{
"version": "0.2.0",
  "configurations": [
    {
      "name": "Electron: Main",
      "type": "node",
      "request": "launch",
      "protocol": "inspector",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "program": "${workspaceFolder}/output/dist/main.dev.bundle.js",
      "args": [
        "--remote-debugging-port=9223",
        "."
      ],
      "windows": {
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd",
        "program": "${workspaceFolder}\\output\\dist\\main.dev.bundle.js",
      },
      "osx": {
        "env": { "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" }
      },
      "outputCapture": "std",
    },
  ],
}

It fails immediately, with above error (shown in a dropdown). No output is generated on the debug console.

Experimentation

I found that making any one of these changes by itself removed the issue:

  1. Setting debug.javascript.usePreview to false, or
  2. Adding line "nodeVersionHint": 12 to the launch.json configuration, or
  3. Launching VS Code from a terminal window that already has the PATH environment variable set up to include /usr/local/bin.

I also found that if I added "nodeVersionHint": 12, but removed the assignment to the PATH from the launch configuration then not surprisingly the debuggger is also unable to start with a similar error. This shows that the "env" setting is having an effect.

Conclusion

I know that when VS Code is launched in the usual way, macOS does not pass it any PATH environment variable. But node is installed in /usr/local/bin and electron is unable to start up without that folder being on the PATH. I'd rather not start code from a terminal. So instead I'm telling VS Code to add the necessary path by using

"osx": {
    "env": { "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" }
},

When VS Code starts electron it is then able to find node. This worked with the old debugger. For the new debugger it still works, provided that I pass in a nodeVersionHint. I conclude that the environment setting is not being passed along when VS Code invokes electron to determine its version. When I pass in a hint, VS Code does not need to invoke electron to find the version, and it subsequently does set the path when it launches electron to start the debug session.

I'm working round the problem (by including the node version hint) but I don't think I should have to do this.

Additional Information

  • macOS: 10.15.7
  • VS Code Version: 1.51.1
  • Version of node installed at /usr/local/bin: v14.15.1
  • Version of electron at ./node_modules/.bin/electron: v8.1.0
@wihd wihd added the bug Issue identified by VS Code Team member as probable bug label Nov 25, 2020
@connor4312
Copy link
Member

Thanks for the great write up. This sounds like microsoft/vscode#106537

@connor4312
Copy link
Member

Closing as tentative duplicate.

@connor4312 connor4312 added the *duplicate Issue identified as a duplicate of another issue(s) label Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

2 participants