rhino
rhino copied to clipboard
RStudio ignores Node.js version set by `nvm`
In RStudio, Node commands are not using Node version set by nvm
. This works fine when the R session is started in the terminal (both R
and radian
):
r$> rhino::diagnostics()
Linux 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022
R version 4.2.1 (2022-06-23)
rhino: 1.1.0
node: v16.16.0
yarn: 1.22.19
and fails in RStudio R console:
> rhino::diagnostics()
Linux 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022
R version 4.2.1 (2022-06-23)
rhino: 1.1.0
node: v14.19.3
yarn: 1.22.19
Related SO question. (Appsilon-internal).
This would be nice to have, I had to install nodejs
and npm
systemwide via apt
to work around this
Notes after discussion with @Leszek-Sieminski.
Root cause
It seems nvm
works on a similar way to pyenv
(version manager for Python): It adds to PATH
its own directory with Node.js binaries. The directory is added at the front of the PATH
, so that the binaries set by nvm
take precedence. Changing the version with nvm use
effectively changes the PATH
to point to a different version.
It follows that PATH
must be configured properly for nvm
to work. The official instructions for nvm
installation ensure that it is the case for shells (like bash or zsh), but they don't cover applications launched via GUI (neither on MacOS nor on Linux).
Possible approaches
-
Handle
nvm
explicitly in Rhino. Rhino could try to findnvm
installation and use it to launch Node.js. This seems to go against UNIX principles and might create problems of its own: What if the user actually wants the currentPATH
to be used? -
Make RStudio pick up
nvm
configuration.-
Launch RStudio from the terminal. This just works (assuming
nvm
is configured properly in the said terminal). -
Configure RStudio to load
nvm
configuration on startup (e.g. source.bashrc
). Not sure if RStudio has such options.
-
Launch RStudio from the terminal. This just works (assuming
-
Setup
nvm
so it works for apps launched via GUI. The graphical display manager also loads some startup files; it is possible that the configuration might be tweaked to also loadnvm
config.
We can reject approach (1). Approaches (2i) and (3) need research: are they viable? We might be able to automate (3) (for example, do it automatically on rhino::init()
), but it's not a light decision (configuring user's system from R package might be costly to implement and risky).
Next step
Research whether approaches (2i) and (3) are viable. Then we can decide what to do next: document and/or automate?
Resources
- The "Using graphical display manager" section in this article on environment variables might be helpful in understanding how approach (3) could be achieved.
Since we are discussing various different ways to address Node installation in general, solutions (2ii) and (3) should wait until it is resolved.
Until then solution (2i) launching RStudio from the terminal is advised for nvm
users. We will document this in the Node vignette and we will come back to this issue when we deal with Node installation.