Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlinked home directory causes persistent "not compatible with prefix option" error #2238

Closed
mvastola opened this issue Jun 13, 2020 · 2 comments

Comments

@mvastola
Copy link

Operating system and version:

Ubuntu 19.10

nvm debug output:

nvm --version: v0.35.3
$SHELL: /bin/bash
$SHLVL: 1
${HOME}: /home/mvastola
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /usr/local/rvm/gems/ruby-2.7.0/bin:/usr/local/rvm/gems/ruby-2.7.0@global/bin:/usr/local/rvm/rubies/ruby-2.7.0/bin:/usr/local/rvm/bin:${HOME}/.local/bin:${HOME}/bin:${HOME}/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/brlcad/bin:${HOME}/.dotnet/tools:/usr/lib/jvm/default-java/bin:/usr/lib/jvm/default-java/db/bin:/usr/lib/jvm/default-java/jre/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)'
uname -a: 'Linux 5.3.0-59-generic #53-Ubuntu SMP Wed Jun 3 15:52:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux'
OS version: Ubuntu 19.10
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.20.2 (+libidn2/2.0.5) libssh/0.9.0/openssl/zlib nghttp2/1.39.2 librtmp/2.3
wget: /usr/bin/wget, GNU Wget 1.20.3 built on linux-gnu.
git: /usr/bin/git, git version 2.20.1
grep: /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: /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.6.0.225-235f
nvm current: none
which node:
which iojs:
which npm:
npm config get prefix:
Command 'npm' not found, but can be installed with:

sudo apt install npm
npm root -g:
Command 'npm' not found, but can be installed with:

sudo apt install npm

Background

On my system, I have my /home folder symlinked to /media/SOME_NAME/home, as my home directories reside on a different partition. I never updated my users' home directories in /etc/passwd because it never seemed necessary (that is, /etc/passwd still contains home directories such as /home/mvastola).

The Issue

Whenever I run nvm use default, however, I get the following error message:

nvm is not compatible with the npm config "prefix" option: currently set to "/media/SOME_NAME/home/mvastola/.nvm/versions/node/v14.4.0"
Run `nvm use --delete-prefix v14.4.0 --silent` to unset it.

The Cause

It appears that this error is occurring due to this line of code in nvm.sh.

Specifically, the command in that line evaluates to: nvm_tree_contains_path /home/mvastola/.nvm /media/SOME_NAME/home/mvastola/.nvm/versions/node/v14.4.0. This function has a non-zero return value, and the error above is generated.

Obviously, the underlying issue is either:
a) that the first path listed (the NVM_DIR environment var set in .bashrc) should be absolute, or;
b) that the second path listed (obtained from running npm config --loglevel=warn get prefix) shouldn't be absolute.

Clearly, (a) is due to the export NVM_DIR="$HOME/.nvm" inserted into .bashrc at install time.

I'm not entirely sure where the second path comes from, but my best guess is that it came from $HOME/.nvm/versions/node/v14.4.0/lib/node_modules/npm/package.json, where _where key contains the absolute path to my home directory.

The Workaround

I was able to patch this issue by simply replacing export NVM_DIR="$HOME/.nvm" in .bashrc to contain the absolute path of home.

The Fix

I'm not sure where the _where key in $HOME/.nvm/versions/node/v14.4.0/lib/node_modules/npm/package.json was set, but if it was set by npm itself, stoping npm from resolving symlinks (or otherwise un-resolving them doesn't seem like a practical solution).

Instead, I would suggest updating the line in .bashrc to be:

export NVM_DIR="$(readlink -e "$HOME")/.nvm"

Please let me know if there's any additional info I can provide or if you have other questions or want me to test alternate solutions.

Note that, per advice in other GitHub issues, I have ensured there are no other instances of npm in any of my PATH directories, and there are no extraneous npmrc files in my filesystem. I have also deleted all non-nvm node_modules folders.

@ljharb
Copy link
Member

ljharb commented Jun 13, 2020

nvm does not currently support $HOME or $NVM_DIR being a symlink; duplicate of #617.

@ljharb ljharb closed this as completed Jun 13, 2020
@mvastola
Copy link
Author

Oh. Thanks. I tried searching but that must have been buried in all the other issues from people getting the prefix error and it being because of .nvmrc or old node installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants