nvm-sh / nvm

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

But I like my prefix! #2687

Closed adamnovak closed 2 years ago

adamnovak commented 2 years ago

I installed nvm by cloning the repo to ~/.nvm and adding the lines specified in the README to my bashrc.

I did this because I need to build a project (https://github.com/aws/amazon-genomics-cli) that has nvm install as one of its build steps, and uses a .nvmrc file. I don't really want to use nvm to manage npm and nodejs in general for my user, beyond being able to follow the build steps for this project. I already use n to change node versions globally for my user. I'm probably going to have to take out the bashrc lines and move them to something I source just for the project, since nvm seems to want to replace n.

For non-nvm-managed Node and NPM, I have prefix set in ~/.npmrc, so that npm install -g can install things somewhere actually writable by me.

nvm has decided to complain in every shell I open that there's a prefix set in my ~/.npmrc. It prompts me to run:

nvm use --delete-prefix v14.18.2 --silent

All that does is delete the prefix option from the file. I need to keep the prefix option around for when I'm not working on this particular project.

Operating system and version:

Ubuntu 20.04

nvm debug output:

```sh nvm --version: v0.39.0 $SHELL: /bin/bash $SHLVL: 1 whoami: 'anovak' ${HOME}: /home/anovak ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${NVM_DIR}/versions/node/v14.18.2/bin:${HOME}/workspace/fdroidserver:/opt/singularity/bin:${HOME}/.cargo/bin:${HOME}/bin:${HOME}/.local/bin:${HOME}/.cargo/bin:${HOME}/bin:${HOME}/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:${HOME}/workspace/cjdns/cjdns/tools:${HOME}/.gopath/bin:/z${HOME}/workspace/vg/bin:/opt/rocm/bin:/opt/rocm/rocprofiler/bin:/opt/rocm/opencl/bin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)' uname -a: 'Linux 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux' checksum binary: 'sha256sum' OS version: Ubuntu 20.04.3 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: /bin/grep (grep --color=auto), grep (GNU grep) 3.4 awk: /usr/bin/awk, GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0) sed: /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: /bin/rm, rm (GNU coreutils) 8.30 mkdir: /bin/mkdir, mkdir (GNU coreutils) 8.30 xargs: /usr/bin/xargs, xargs (GNU findutils) 4.7.0 nvm current: v14.18.2 which node: ${NVM_DIR}/versions/node/v14.18.2/bin/node which iojs: which npm: ${NVM_DIR}/versions/node/v14.18.2/bin/npm npm config get prefix: ${NVM_DIR}/versions/node/v14.18.2 npm root -g: ${NVM_DIR}/versions/node/v14.18.2/lib/node_modules ```

nvm ls output:

```sh -> v14.18.2 system default -> 14 (-> v14.18.2) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v14.18.2) (default) stable -> 14.18 (-> v14.18.2) (default) lts/* -> lts/gallium (-> 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.7 (-> N/A) lts/fermium -> v14.18.2 lts/gallium -> v16.13.1 (-> N/A) ```

How did you install nvm?

I installed nvm by cloning the repo to ~/.nvm and adding the lines specified in the README to my bashrc.

I installed it after already having a working npm setup for installing packages with -g under my home directory, that I don't want to dismantle just so I can build a tool that uses nvm in its build process.

What steps did you perform?

Open a shell or run any nvm command.

What happened?

It complained about my ~/.npmrc file having the prefix directive, and prompted me to remove it.

What did you expect to happen?

nvm should be self-contained and not demand that I delete the prefix directive that I am using for other Node/npm installs.

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

Yes, all sorts of stuff modifies my PATH. None of it seems relevant here though.

ljharb commented 2 years ago

You should be able to use both nvm and n simultaneously, in a general sense.

The auto-sourcing of nvm shouldn't cause any issue - you may need to nvm unalias default, though, to prevent it auto-using a version and shadowing the "system" one n installs.

As for the prefix, that's why you should be using nvm :-) that way you don't have to overwrite npm root -g so as to avoid sudo.

nvm is not self-contained in the fashion you want. If you want to use it at all, you can't use prefix. There's really no way around that except perhaps setting the prefix in an NPM_CONFIG_PREFIX env var (instead of .npmrc), and then unsetting that env var in the shell you're using to work with this one project.

This is really an issue with that specific project hardcoding in a version manager - as much as I'm glad they chose nvm, it'd be the same issue if they'd chosen anything else that you weren't already using. By them choosing to force a version manager, to develop it, you're simply forced to adjust.

adamnovak commented 2 years ago

It's not quite as forced as it could be; it's just specified to be used in the README, not in the actual Makefile.

I'll try doing my prefix as NPM_CONFIG_PREFIX, which is easier to change around than editing the config file back and forth when I want to use or not use nvm.