rhino icon indicating copy to clipboard operation
rhino copied to clipboard

RStudio ignores Node.js version set by `nvm`

Open kamilzyla opened this issue 2 years ago • 1 comments

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

kamilzyla avatar Oct 03 '22 12:10 kamilzyla

Related SO question. (Appsilon-internal).

kamilzyla avatar Oct 17 '22 08:10 kamilzyla

This would be nice to have, I had to install nodejs and npm systemwide via apt to work around this

averissimo avatar Nov 08 '22 11:11 averissimo

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

  1. Handle nvm explicitly in Rhino. Rhino could try to find nvm 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 current PATH to be used?
  2. Make RStudio pick up nvm configuration.
    1. Launch RStudio from the terminal. This just works (assuming nvm is configured properly in the said terminal).
    2. Configure RStudio to load nvm configuration on startup (e.g. source .bashrc). Not sure if RStudio has such options.
  3. 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 load nvm 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

  1. The "Using graphical display manager" section in this article on environment variables might be helpful in understanding how approach (3) could be achieved.

kamilzyla avatar Nov 15 '22 14:11 kamilzyla

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.

Leszek-Sieminski avatar Nov 16 '22 10:11 Leszek-Sieminski