Skip to content

oh-my-zsh: NVM is not compatible with the npm config "prefix" option #855

Closed
@fabdrol

Description

@fabdrol

Very annoying issue; every time I want to use node or NPM, I get this error and need to run a command to solve it.

nvm is not compatible with the npm config "prefix" option: currently set to "/Users/fabian/.nvm/versions/node/v0.12.7"
Run `nvm use --delete-prefix v0.12.7` to unset it.

Activity

ljharb

ljharb commented on Oct 1, 2015

@ljharb
Member

Thanks for the report! What does nvm deactivate ; nvm debug ; echo $PREFIX ; echo $NPM_CONFIG_PREFIX print out?

added
needs followupWe need some info or action from whoever filed this issue/PR.
on Oct 1, 2015
fabdrol

fabdrol commented on Oct 2, 2015

@fabdrol
Author
Could not find /Users/Fabian/.nvm/*/bin in $PATH
Could not find /Users/Fabian/.nvm/*/share/man in $MANPATH
$SHELL: /bin/zsh
$NVM_DIR: /Users/Fabian/.nvm
nvm current: none
which node: node not found
which iojs: iojs not found
which npm: npm not found
npm config get prefix: nvm:74: command not found: npm
npm root -g: nvm:74: command not found: npm
ljharb

ljharb commented on Oct 2, 2015

@ljharb
Member

and the env vars?

fabdrol

fabdrol commented on Oct 2, 2015

@fabdrol
Author
PATH=.:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/local/heroku/bin:/usr/local/mysql/bin:/usr/local/git/bin:/usr/local/mongodb/bin:/usr/bin:/usr/sbin:/usr/local/lib/AIRSDK:/usr/local/lib/AIRSDK/bin:/Users/fabian:/Users/fabian/bin:/Users/fabian/.bin:/Users/fabian/.phpdoc/bin:/Users/fabian/pear/bin:/Users/fabian/.composer/vendor/bin:/Users/fabian/android.ndk:/Users/fabian/android.sdk/r24.3.4:/Users/fabian/android.sdk/r24.3.4/tools:/Volumes/Hyper/Development/Go/bin:/Library/Java/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
TMPDIR=/var/folders/mp/hd4fy3n15z17_g9s4j11y8gm0000gn/T/
LOGNAME=fabian
XPC_FLAGS=0x0
HOME=/Users/fabian
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.WrQOEzC6ut/Render
TERM=xterm-256color
COLORFGBG=7;0
USER=fabian
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.FEGVlgCDcM/Listeners
ITERM_PROFILE=Default
TERM_PROGRAM=iTerm.app
XPC_SERVICE_NAME=0
SHELL=/bin/zsh
ITERM_SESSION_ID=w0t0p0
PWD=/Users/fabian
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
LC_CTYPE=UTF-8
SHLVL=1
OLDPWD=/Users/fabian
ZSH=/Users/fabian/.oh-my-zsh
LANG=en_US.UTF-8
GOPATH=/Volumes/Hyper/Development/Go
NODE_PATH=/usr/local/bin/node
NODE_HOME=/usr/local/lib/node
JAVA_HOME=/Library/Java/Home
ANDROID_SDK=/Users/fabian/android.sdk/r24.3.4
ANDROID_NDK=/Users/fabian/android.ndk
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
LS_COLORS=no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:
NVM_DIR=/Users/Fabian/.nvm
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
MANPATH=/usr/share/man:/usr/local/share/man:/usr/local/mysql/man:/Applications/Xcode.app/Contents/Developer/usr/share/man:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/share/man
NVM_PATH=/Users/Fabian/.nvm/versions/node/v0.12.7/lib/node
NVM_BIN=/Users/Fabian/.nvm/versions/node/v0.12.7/bin
_=/usr/bin/printenv
ljharb

ljharb commented on Oct 2, 2015

@ljharb
Member

Thanks! so, clearly you don't have an npm prefix set.

Are you by chance using oh-my-zsh? That tends to set tons of opts that nvm has to manually account for.

fabdrol

fabdrol commented on Oct 2, 2015

@fabdrol
Author

Yeah, I am.. I could manually set it, I assume? How do I go about that?

ljharb

ljharb commented on Oct 2, 2015

@ljharb
Member

If you try to set the "prefix" that will break nvm.

As a temporary workaround, you can do nvm use --delete-prefix v0.12.7, but this is a bug specifically with omz. I'll have to figure out which option to unset when doing the comparison.

added
bugsOh no, something's broken :-(
and removed
needs followupWe need some info or action from whoever filed this issue/PR.
on Oct 2, 2015
self-assigned this
on Oct 2, 2015
changed the title [-]NVM is not compatible with the npm config "prefix" option[/-] [+]oh-my-zsh: NVM is not compatible with the npm config "prefix" option[/+] on Oct 2, 2015
fabdrol

fabdrol commented on Oct 2, 2015

@fabdrol
Author

Okay, let me know if I can help with anything!

ljharb

ljharb commented on Oct 2, 2015

@ljharb
Member

Could you provide the output of setopt as well? From there I should be able to try to debug it.

351 remaining items

ljharb

ljharb commented on Jul 10, 2020

@ljharb
olivermg

olivermg commented on Sep 16, 2020

@olivermg

@vegetabill specifically, nvm does not support the home dir being a symlink (and many other tools may not either). I'd suggest to your org's dev ops team that they use a hard link or a mount, rather than a symlink.

I'm on FreeBSD, where /home is a symlink to /usr/home by default, effectively triggering the error regarding the prefix, probably for each and every FreeBSD installation (and potentially other Unix flavors) out there.

Disallowing symlinks within one's home path thus doesn't seem to be a very portable way of looking at things.

Maybe stuff like readlink -f and/or pwd -P might help to create more portable scripts.

ljharb

ljharb commented on Sep 17, 2020

@ljharb
Member

@olivermg that's new information for me, and quite unfortunate, but I'm very surprised that over the 6-8 years nvm has been around, no FreeBSD user has reported this before :-/

See #2143 and #617 for things relevant to symlinks.

olivermg

olivermg commented on Sep 17, 2020

@olivermg

@ljharb For more info, I've just installed a few recent BSDs in VMs:

All the following FreeBSD installations set /home to a symlink to /usr/home, while also setting $HOME to /home/myuser (chshing from the default shell sh to bash does not seem to make a difference to the value of $HOME):

  • FreeBSD 12.1 default installation (thus UFS filesystem)
  • FreeBSD 12.1 with ZFS filesystem instead of UFS
  • FreeBSD 11.4 default installation (thus UFS filesystem)
  • FreeBSD 13-CURRENT default installation (thus ZFS filesystem)

The following BSDs don't seem to use symlinks in home paths though:

  • OpenBSD 6.7
  • NetBSD 9.0
olivermg

olivermg commented on Sep 17, 2020

@olivermg

@ljharb Btw, if it's coming in handy for you I can start working on a PR regarding this issue (i.e. supporting OSes that do use symlinks in home paths).

Moreover, this is probably a new distinct issue, as it is not related to zsh.


UPDATE: I understand there is already a PR going into this direction in #2143 . Let's see if your request for finishing that PR actually triggers a response ;-) . If not I'll maybe look into it.

ljharb

ljharb commented on Sep 17, 2020

@ljharb
Member

@olivermg it would also be awesome if you wanted to just comment on #2143 with a link to your own branch that builds off of it - i can easily pull in those commits, even if the OP doesn't respond. I'd love to improve the workflow here, just because nvm hasn't worked with symlinks for awhile doesn't mean it doesn't suck that it doesn't :-)

olivermg

olivermg commented on Sep 20, 2020

@olivermg

Btw, just noticed that Fedora Silverblue also uses symlinks in home paths:

$ ls -lad /home
lrwxrwxrwx. 3 root root 8 Feb 22  2020 /home -> var/home

UPDATE: However, it doesn't seem to be triggering the prefix error message (like e.g. on FreeBSD), as Fedora seems to set $HOME to the physical path (so without a symlink in it).

AnshulSurana

AnshulSurana commented on Oct 13, 2020

@AnshulSurana

@sricharankrishnan remove the prefix line in ~/.npmrc

Cannot change root .npmrc as it is locked for change.

ljharb

ljharb commented on Oct 13, 2020

@ljharb
Member

@AnshulSurana that's not the root npmrc, that's your user npmrc, and you should always have full control of anything in ~. If you can't remove that line, then unfortunately you can't use nvm, because the two things are incompatible.

Xananax

Xananax commented on Nov 26, 2020

@Xananax

I do not use oh-my-zsh, I use ZimFW, but I'll still tag along because I think it's related.

My flavor of this is pretty damn weird. When I open a terminal, I get:

grep: Desktop: Is a directory
grep: Downloads: Is a directory
...etc

This also happens on TTY, with no graphical server running at all.

In specific directories, I get weird stuff, like:

grep: node_modules: Is a directory
grep: out: Is a directory
grep: src: Is a directory
grep: static: Is a directory 
(eval):1: command not found: forge.config.js
nvm is not compatible with the "README.md:- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)" environment variable: currently set to ".md:- [](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)"
Run `unset README.md:- [\`forge.config.js\`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)` to unset it.

Of course, the sentence

- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)

is part of my README.md and describes the project's architecture.

The string forge.config.js only exists in the README.md and as a config key in `package.json.

> grep -R "forge.config.js" --exclude-dir node_modules
package.json:    "forge": "./forge.config.js"
README.md:- [`forge.config.js`](./forge.config.js): decides which packages are used by Electron Forge. In particular, it sets the exporters (Windows, Mac, Linux, ...)

If I remove that sentence from the README, then nvm tells me this:

nvm is not compatible with the "package.json:    "forge": "./forge.config.js"" environment variable: currently set to ".json:    forge: ./forge.config.js"

If I remove that, then I only get the directories issues described above. Removing only the line in package.json isn't sufficient, however.

So nvm is deciding on its own to... parse the README.md, extract that string for some reason, then eval it? Then decide that there's an environment variable equal to the whole line?

Notice the environment variable's name starts with README.md: ... but it's set to .md: ...

I can confirm these issues come from nvm, because if I do not source nvm.sh, I get none of this. Using bash fixes the problem too, so this some kind of mix between nvm and zsh.

Apart for these annoying notices, nvm is working as expected, as far as I can tell.

ljharb

ljharb commented on Nov 27, 2020

@ljharb
Member

This issue was resolved in v0.37.0 with #2317

@Xananax would you mind filing that as a new issue, with the full issue template filled out?

vunderkind

vunderkind commented on Dec 21, 2022

@vunderkind

This turned out to be the fix for me. Uninstalled npm and the error was gone. Now to re-install it and see if I'm in the clear.

Lots of people above have provided solutions to this including reinstall node, uninstall brew node, reinstall nvm etc.

But really the only essential step you need to do is to remove the wrong npm reference applied before your nvm script path settings.

Most of the time this is /usr/loca/bin/npm

Which means you just need to do rm /usr/loca/bin/npm and restart your terminal.

If this doesn't solve the problem, you can run which npm before your nvm path setting script to find out what is it, and just remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @heycarsten@bryansray@reybango@pdeka@eldoy

      Issue actions

        oh-my-zsh: NVM is not compatible with the npm config "prefix" option · Issue #855 · nvm-sh/nvm