Nvm: No npm prefix set, but nvm requires 'nvm use --delete-prefix'

Created on 13 Aug 2019  Ā·  11Comments  Ā·  Source: nvm-sh/nvm

  • Operating system and version:

$ lsb_release -a
LSB Version:    1.4
Distributor ID: Arch
Description:    Arch Linux
Release:    rolling
Codename:   n/a

  • nvm debug output:

$ nvm debug
nvm --version: v0.34.0
$SHELL: /bin/bash
$SHLVL: 2
$HOME: /home/paulk/
$NVM_DIR: '$HOME/.nvm'
$PATH: /usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/lib32/jvm/default/bin:/opt/ti/msp-flasher:/opt/ti/mspgcc/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:$HOME/bin/:$HOME.gem/ruby/2.3.0/bin:/opt/android-sdk/platform-tools/:$HOME.bin:$HOMEbin/gyb:
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.0.7(1)-release (x86_64-pc-linux-gnu)'
uname -a: 'Linux 5.1.15-zen1-1-zen #1 ZEN SMP PREEMPT Tue Jun 25 04:49:28 UTC 2019 x86_64 GNU/Linux'
OS version: Arch Linux  ()
curl: /usr/bin/curl, curl 7.65.3 (x86_64-pc-linux-gnu) libcurl/7.65.3 OpenSSL/1.1.1c zlib/1.2.11 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh2/1.8.2 nghttp2/1.36.0
wget: /usr/bin/wget, GNU Wget 1.20.3 built on linux-gnu.
git: /usr/bin/git, git version 2.22.0
grep: /usr/bin/grep (grep --color=auto), grep (GNU grep) 3.3
awk: /usr/bin/awk, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
sed: /usr/bin/sed, sed (GNU sed) 4.7
cut: /usr/bin/cut, cut (GNU coreutils) 8.31
basename: /usr/bin/basename, basename (GNU coreutils) 8.31
rm: /usr/bin/rm, rm (GNU coreutils) 8.31
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.31
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.6.0
nvm current: system
which node: /usr/bin/node
which iojs: which: no iojs in (/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/lib32/jvm/default/bin:/opt/ti/msp-flasher:/opt/ti/mspgcc/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:$HOME/bin/:$HOME.gem/ruby/2.3.0/bin:/opt/android-sdk/platform-tools/:$HOME.bin:$HOMEbin/gyb:)
which npm: /usr/bin/npm
npm config get prefix: /usr
npm root -g: /usr/lib/node_modules

  • nvm ls output:

$ nvm ls
        v8.16.0
       v10.16.2
->       system
node -> stable (-> v10.16.2) (default)
stable -> 10.16 (-> v10.16.2) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/dubnium (-> v10.16.2)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.0
lts/dubnium -> v10.16.2

</details>

- How did you install `nvm`? (e.g. install script in readme, Homebrew):
nvm installed from https://aur.archlinux.org/packages/nvm/
My ~/.bashrc ends with:
<details>

  <!-- do not delete the following blank line -->

```sh
export PATH="$PATH:$(yarn global bin)"
export NVM_DIR="$HOME/.nvm"
source /usr/share/nvm/init-nvm.sh

  • What steps did you perform?
    Anytime I run nvm use {NODE_VERSION} it complains

nvm is not compatible with the npm config "prefix" option: currently set to "/home/paulk/.nvm/versions/node/v{NODE_VERSION}"
Run `npm config delete prefix` or `nvm use --delete-prefix v{NODE_VERSION}` to unset it.

If I set a default alias, then the error message appears anytime I open a shell. NVM seems to work just fine if I use nvm use --delete-prefix every time I try to load a different NVM version.

  • What did you expect to happen?
    I expected nvm to silently switch to the specified node. I'd like to be able to set a default prefix.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?
    Yes, but it's all before the lines that load nvm.

My ~/.npmrc contains only the local-address=10.1.2.123 option.

feature requests pull request wanted

All 11 comments

Is your $HOME or $NVM_DIR a symlink, perhaps?

No.

$ ls -lahd $HOME
drwxr-xr-x 172 paulk paulk 12K Aug 13 10:18 /home/paulk/
$ ls -lahd $NVM_DIR
drwxr-xr-x 5 paulk paulk 79 Aug 13 10:12 /home/paulk//.nvm

But some of the stuff in my $NVM_DIR are simlinks:

$ ls -lah $NVM_DIR
total 16K
drwxr-xr-x   5 paulk paulk  79 Aug 13 10:12 .
drwxr-xr-x 172 paulk paulk 12K Aug 13 10:18 ..
drwxr-xr-x   3 paulk paulk  17 Aug 13 10:14 alias
drwxr-xr-x   3 paulk paulk  17 Aug 13 10:12 .cache
lrwxrwxrwx   1 paulk paulk  23 Aug 13 10:12 nvm-exec -> /usr/share/nvm/nvm-exec
lrwxrwxrwx   1 paulk paulk  21 Aug 13 10:12 nvm.sh -> /usr/share/nvm/nvm.sh
drwxr-xr-x   3 paulk paulk  18 Aug 13 10:12 versions

hmm, that might be the issue - nvm.sh in particular needs to be a proper file inside NVM_DIR.

Looks like it's caused by the extra / in $NVM_DIR.

$ nvm use lts/carbon
nvm is not compatible with the npm config "prefix" option: currently set to "/home/paulk/.nvm/versions/node/v8.16.0"
Run `npm config delete prefix` or `nvm use --delete-prefix v8.16.0` to unset it.
$ nvm use lts/carbon
nvm is not compatible with the npm config "prefix" option: currently set to "/home/paulk/.nvm/versions/node/v8.16.0"
Run `npm config delete prefix` or `nvm use --delete-prefix v8.16.0` to unset it.
$ export NVM_DIR=/home/paulk/.nvm
$ nvm use lts/carbon
Now using node v8.16.0 (npm v6.4.1)

aha, yes. does $HOME have an extra slash in it?

I see that it does. $HOME is a directory path, and the trailing slash means ā€œinside the dirā€. If you fix that in your profile files, you should be fine.

Funny, I had and could fix exactly the same problem this way this morning! Remove the trailing slash in $HOME https://serverfault.com/questions/876317/what-to-do-with-trailing-slash-in-home-on-centos

I have other things that expect the trailing slash in the $HOME, so I fixed it when declaring $NPM_HOME instead.

I would still consider this a bug and encourage you to fix whatever is parsing this. In shell, a path of /////usr/var/./././././////././././//log/ is valid and collapses to /usr/var/log. I know some languages have libraries that will normalize paths for you (os.path.abspath() in python for example).

Those other things are incorrect; a trailing slash makes it not a directory.

That said, #1708 / #1734 fixed this for NVM_DIR; it seems reasonable to fix broken $HOME vars as well.

For those coming here and you are using a Mac, my issue was that my user folder had upper case letters in it, but my profile folder setting under users pointed to the all lower case path version of it. Once I logged in from another account renamed to have all lower case all worked just fine.

Just updated to Catalina (10.15.1) and had same issue
Deleting /usr/local/bin/npm solved my issue
And then I had to reinstall node as npm just stopped working

Was this page helpful?
0 / 5 - 0 ratings