vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

ELECTRON_RUN_AS_NODE is inherited from the VSCode environment when building a CMake target

Open brechtm opened this issue 3 years ago • 3 comments

I have defined a custom CMake target to build our documentation using the Python tool Sphinx. As part of the documentation building process, drawio, an Electron based application, is executed and fails with the following error message: drawio: bad option --export. This only occurs when building the CMake target using the CMake Tools VSCode extension. There is no problem when running the target from a terminal, inside or outside of VSCode. Also invoking Sphinx from a VSCode launch/debug configuration is without issues.

I have found that the root cause for this is that Electron applications behave like this when the ELECTRON_RUN_AS_NODE environment variable is set (see https://github.com/electron/electron/issues/18412). VSCode cleans the environment for its terminals and when starting debug sessions. I believe CMake Tools should do the same when building a target, making sure it doesn't affect VSCode's environment.

Platform and Versions

  • Operating System: Ubuntu 18.04
  • CMake Version: 3.17.4
  • VSCode Version: 1.51.0
  • CMake Tools Extension Version: 1.5.2

brechtm avatar Nov 12 '20 13:11 brechtm

Thank you for the feature idea. We may not be able to implement it immediately, but we will track the community reactions to determine where this might fit into our backlog.

andreeis avatar Nov 12 '20 14:11 andreeis

I have a similar problem with the LaTeX Workshop for the VS CODE. I know this thread for CMAKE but decided to report it because it seems to have the same root cause.

I created a small script file that runs the drawio. This script works fine when I invoke it from the command line. Bunt once it is called as a sub process of the VS CODE LaTeX Workshop, it doesn't work. I dug it and found the drawio shows the following error when it is invoked from the LaTeX Workshop of the VS CODE

drawio: bad option: -xf

Platform and Versions

  • Operating System: Ubuntu 22.04
  • VSCode Version: 1.69.2
  • LaTeX Workshop: v8.27.2

suikan4github avatar Jul 23 '22 23:07 suikan4github

I found a workaround for my case. To call the drawio from Visual Studio Code, wrap it by shell script.

#!/bin/bash

export -n ELECTRON_RUN_AS_NODE
drawio ... parameters ... 

Name it for example call_drawio.sh and call it from VS Code. It works for me.

The "export -n" requires bash.

suikan4github avatar Jul 31 '22 22:07 suikan4github

I also had the same problem when calling drawio from a latexmk cusdep. Thanks to this issue I solved it by adding this to my .latexmkrc

add_cus_dep('drawio', 'pdf', 0, 'drawio2pdf');
sub drawio2pdf {
   $ENV{'ELECTRON_RUN_AS_NODE'} = '';
   my $return = system "draw.io --crop -x -f pdf -o $_[0].pdf $_[0].drawio";
   return $return;
}

NicolasHaeffner avatar Nov 02 '22 11:11 NicolasHaeffner