nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
78.56k stars 7.87k forks source link

`.nvmrc` causes conflict with `nvm install` #2430

Open gmemstr opened 3 years ago

gmemstr commented 3 years ago

Operating system and version:

Any, as far as I can tell. Tested:

macOS Ubuntu 20.04

using CircleCI.

nvm debug output:

```sh nvm --version: v0.35.3 $SHELL: /bin/sh $SHLVL: 1 ${HOME}: /home/circleci ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${HOME}/bin:${HOME}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' /bin/sh: 0: Illegal option -- shell version: '' uname -a: 'Linux 4.15.0-1092-aws #98-Ubuntu SMP Wed Jan 6 22:22:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux' OS version: Ubuntu 20.04.1 LTS curl: /usr/bin/curl, curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3 wget: /usr/bin/wget, GNU Wget 1.20.3 built on linux-gnu. git: /usr/bin/git, git version 2.25.1 grep: /usr/bin/grep (grep --color=auto), grep (GNU grep) 3.4 awk: /usr/bin/awk, awk: not an option: --version sed: /usr/bin/sed, sed (GNU sed) 4.7 cut: /usr/bin/cut, cut (GNU coreutils) 8.30 basename: /usr/bin/basename, basename (GNU coreutils) 8.30 rm: /usr/bin/rm, rm (GNU coreutils) 8.30 mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.30 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0 nvm current: none which node: which iojs: which npm: npm config get prefix: -bash: npm: command not found npm root -g: -bash: npm: command not found ```

nvm ls output:

```sh N/A iojs -> N/A (default) node -> stable (-> N/A) (default) unstable -> N/A (default) ```

How did you install nvm?

Install script in README.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
NVM_DIR="$HOME/.nvm"
echo "export NVM_DIR=\"$HOME/.nvm\"" >> $BASH_ENV
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && \. \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
source $BASH_ENV
nvm install \
 node  

What steps did you perform?

Performed above install commands to pull in the script and modify our PATH.

What happened?

nvm does not appear to know how to behave when a nvmrc file is present, and borks the install process, claiming "N/A" is not installed yet.

``` % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13527 100 13527 0 0 244k 0 --:--:-- --:--:-- --:--:-- 244k => Downloading nvm from git to '/home/circleci/.nvm' => Cloning into '/home/circleci/.nvm'... remote: Enumerating objects: 290, done. remote: Counting objects: 100% (290/290), done. remote: Compressing objects: 100% (257/257), done. remote: Total 290 (delta 34), reused 111 (delta 20), pack-reused 0 Receiving objects: 100% (290/290), 163.37 KiB | 7.10 MiB/s, done. Resolving deltas: 100% (34/34), done. => Compressing and cleaning up git repository => Appending nvm source string to /home/circleci/.bashrc => Appending bash_completion source string to /home/circleci/.bashrc N/A: version "12.13.0 -> N/A" is not yet installed. You need to run "nvm install 12.13.0" to install it before using it. => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion N/A: version "12.13.0 -> N/A" is not yet installed. You need to run "nvm install 12.13.0" to install it before using it. Exited with code exit status 3 ``` ``` $ cat .nvmrc 12.13.0 ```

What did you expect to happen?

nvm correctly installs Node version specified in .nvmrc.

Is there anything in any of your profile files that modifies the PATH?

No.

ljharb commented 3 years ago

That’s because the command that sources nvm attempts to auto-use the version in nvmrc. You can add --install to the source line and it will auto-install at source time - then you don’t need a separate nvm install command unless you actually want to install a different version (“node” refers to v15 atm, whereas your nvmrc wants v12).

the other alternative is to source nvm before cd-ing into a directory with an nvmrc.