This is with nvm v0.40.3 on Debian 12.
The Problem
The documentation says that
...nvm which will use the version specified in the .nvmrc file if no version is supplied on the command line.
The help output says:
nvm which [current | ]
Display path to installed node version. Uses .nvmrc if available and version is omitted.
These are all correct, but the design is annoying because npm which fails if there is no .nvmrc found:
$ nvm which
No .nvmrc file found
[...full help output here deleted...]
$ echo exitcode=$?
exitcode=127
In this case you must use nvm which current, which always shows the version that would be selected if .nvmrc were not found. (A related problem: nvm current does the same.)
Solutions
Probably nvm which should be changed to use current if no .nvmrc is found. Without this, it's a bunch of extra work to reliably use nvm which when a .nvmrc file may or may not be present.
It's unclear to me what current is supposed to mean, and this appears to be undocumented. Is it the version of node in the path, if present, or the version that will be used by nvm exec etc? (These are not the same if a .nvmrc file is present.) I just noticed that nvm exec etc. accept an undocumented current argument for the version, where it appears to be the latter:
$ nvm current
v24.11.1
$ nvm which
Found '/home/cjs/tmp/nvm/.nvmrc' with version <v22>
/home/cjs/.nvm/versions/node/v22.20.0/bin/node
$ nvm which current
/home/cjs/.nvm/versions/node/v24.11.1/bin/node
$ nvm exec true
Found '/home/cjs/tmp/nvm/.nvmrc' with version <v22>
Running node v22.20.0 (npm v11.6.2)
$ nvm exec current true
Running node v24.11.1 (npm v11.6.2)
So probably the documentation should be updated to indicate what current is and exactly how it works, including documenting current in the help output for all subcommands that accept it.
This is with nvm v0.40.3 on Debian 12.
The Problem
The documentation says that
The help output says:
These are all correct, but the design is annoying because
npm whichfails if there is no.nvmrcfound:In this case you must use
nvm which current, which always shows the version that would be selected if.nvmrcwere not found. (A related problem:nvm currentdoes the same.)Solutions
Probably
nvm whichshould be changed to usecurrentif no.nvmrcis found. Without this, it's a bunch of extra work to reliably usenvm whichwhen a.nvmrcfile may or may not be present.It's unclear to me what
currentis supposed to mean, and this appears to be undocumented. Is it the version ofnodein the path, if present, or the version that will be used bynvm execetc? (These are not the same if a.nvmrcfile is present.) I just noticed thatnvm execetc. accept an undocumentedcurrentargument for the version, where it appears to be the latter:So probably the documentation should be updated to indicate what
currentis and exactly how it works, including documentingcurrentin the help output for all subcommands that accept it.