nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`lts/` aliases change with new releases rather than finding the highest local match

jtnz opened this issue · comments

Operating system and version:

Arch Linux and Amazon Linux 2023 (and probably macOS)

nvm ls output:

$ nvm ls
->     v18.19.1
       v20.11.1
default -> 20.11.1 (-> v20.11.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v20.11.1) (default)
stable -> 20.11 (-> v20.11.1) (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.2 (-> N/A)
lts/iron -> v20.12.2 (-> N/A)

How did you install nvm?

Cloned repo to ~/.nvm, source nvm.sh in .bashrc.

What steps did you perform?

We install two specific versions of Node (current at the time we set it up): 18.19.1 and 20.11.1

What happened?

We then put this in our projects:

$ cat .nvmrc
lts/hydrogen

What did you expect to happen?

We wrote some simple bash tooling to install nvm and two node versions we were interested in. We assumed you could use lts/hydrogen in .nvmrc and it would find the highest v18 installed. This worked at first, but I guess when a newer release of Hydrogen came out and nvm updated, nvm was no longer considers 18.19.1 a valid version of Hydrogen.

We don't want to hard code versions all over our projects as this makes it much harder to manage nvm/node across all of our developer machines/CI. Say some CVE was discovered in node, we'd have to update all repos to fix it. With our tooling we simply have to just update one place.

This is what used to happen:

Found '/home/jenkins/workspace/foo-bar_main/.nvmrc' with version <lts/hydrogen>
16:41:49  Now using node v18.19.1 (npm v10.2.4)

But a few weeks later...

Found '/home/jenkins/workspace/foo-bar_main/.nvmrc' with version <lts/hydrogen>
10:33:48  N/A: version "lts/hydrogen -> v18.20.0" is not yet installed.

As a hack workaround, could we pin nvm at a certain version to avoid it "knowing" of newer versions? Or is there some remote aspect of nvm we can't easily stop?

Indeed, any remote nvm command will update its local "knowledge" of LTS lines.

I suppose you could try locking permissions on $NVM_DIR/alias/lts, but then you'd have to remember to update it in the future.

We've come up with a better hack solution:

$ nvm install 18.19.1
$ nvm alias lts-hydrogen v18.19.1
$ cat .nvmrc
lts-hydrogen
$ nvm use
Found '/some/dir/.nvmrc' with version <lts-hydrogen>
Now using node v18.19.1 (npm v10.2.4)

sure, a custom alias works for that.

this is still an actual issue, though, which is covered by #3198 and #1651.