Skip to content

NVM is not compatible with the npm config "prefix" option warning (OS X) #1245

Description

@peteringraham

Split off from #855 ; see that issue for a similar problem.

This is in OS X El Capitan, 10.11.6 . This error appears on starting a new shell:

nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run `npm config delete prefix` or `nvm use --delete-prefix v5.7.1 --silent` to unset it.

With the usual command in the .bashrc file:

export NVM_DIR="/Users/pingraham/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

Running either or both of the suggested fixes don't appear to do anything, though.

Note: I foolishly installed some node version globally while trying to fix this, and also foolishly upgraded npm once in an attempt to fix this, but ran into an entirely different npm bug ( npm/npm#13918 , if you're curious ) before giving up. On the other hand, NVM seems to sorta work anyway...? Maybe?

Here's some commands & their results:

node -v
v5.7.1

nvm use 5.7.1
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run `npm config delete prefix` or `nvm use --delete-prefix v5.7.1` to unset it.

Running either or both of the suggested command doesn't change anything.

Oddly enough, the switch seems to work anyway... maybe...

nvm use 0.10
Now using node v0.10.33 (npm v1.4.28)

node -v
v0.10.33

nvm use 5.7.1
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run `npm config delete prefix` or `nvm use --delete-prefix v5.7.1` to unset it.

node -v
v5.7.1

(I guess it happened regardless??)

Debugging info:

echo $PREFIX ; echo $NPM_CONFIG_PREFIX

(nothing, just empty lines)

nvm debug
nvm --version: v0.32.0
$SHELL: /bin/bash
$HOME: /Users/pingraham
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: system
which node: /usr/local/bin/node
which iojs: 
which npm: /usr/local/bin/npm
npm config get prefix: /usr/local
npm root -g: /usr/local/lib/node_modules

(nvm debug, after switching)

nvm current: v0.10.33
which node: $NVM_DIR/v0.10.33/bin/node
which iojs: 
which npm: $NVM_DIR/v0.10.33/bin/npm
npm config get prefix: $NVM_DIR/v0.10.33
npm root -g: $NVM_DIR/v0.10.33/lib/node_modules

nvm ls
       v0.10.33  
         v5.7.1  
->       system  
default -> 5.7.1 (-> v5.7.1)
node -> stable (-> v5.7.1) (default)
stable -> 5.7 (-> v5.7.1) (default)
iojs -> N/A (default)
lts/* -> lts/argon (-> N/A)
lts/argon -> v4.5.0 (-> N/A)

No prefixes set in the environment, either:

$PREFIX: ''
$NPM_CONFIG_PREFIX: ''

It seems wrong to just ignore the error! Any ideas on what I could change? And is it a "Real" error, or just noise, since it seems that at least node -v acknowledges the switches anyway?

Activity

  1. ljharb commented on Sep 26, 2016

    @ljharb
    Member

    (also per #855 (comment), you don't have any "prefix" in any .npmrc files, and per #855 (comment), you don't have any case-insensitive form of "prefix" in env)

    I assume that nvm ls, after the nvm use, has the -> pointing at "v5.7.1"?

    Do you have anything in ~/.bash_profile and/or ~/.bashrc that refers to PATH, nvm, or npm?

    I'm seeing a few strange things here:

    • nvm use complains about the prefix, but you don't have any prefix overrides set anywhere
    • when nvm use complains about the prefix, the node version still changes (it should be running nvm deactivate after printing that error)
  2. peteringraham commented on Sep 26, 2016

    @peteringraham
    Author

    I don't believe so, as far as PATH /nvm / npm references of note. My ~/.bash_profile:

    source ~/.bashrc
    
    if [ -f ~/.git-completion.bash ]; then
      . ~/.git-completion.bash
    fi
    

    The source of the bashrc seems like it shouldn't really be necessary to me, but .bashrc doesn't run if I don't include it.

    The only thing in .bashrc of potential interest is pretty bog-standard:

    export NVM_DIR="/Users/pingraham/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
    
    eval "$(grunt --completion=bash)"
    

    For nvm ls: Not that one version. If I use 5.7.1, it points to "system" instead (which is hopefully harmless, since node -v indicates system IS 5.7.1 ). npm -v says it is 3.6.0. If I use some other version (e.g. v.0.10.36), then it points to that, yes (and npm -v gives 2.20 ).

    (after terminal start, or nvm use 5.7.1)
    
    nvm ls
           v0.10.33  
           v0.10.36  
             v5.7.1  
    ->       system  
    default -> 5.7.1 (-> v5.7.1)
    node -> stable (-> v5.7.1) (default)
    stable -> 5.7 (-> v5.7.1) (default)
    iojs -> N/A (default)
    lts/* -> lts/argon (-> N/A)
    lts/argon -> v4.5.0 (-> N/A)
    

    Thanks for looking into this!

  3. ljharb commented on Sep 26, 2016

    @ljharb
    Member

    @peteringraham hm, it's possible that v5.7.1 is corrupted? could you try nvm uninstall v5.7.1 && nvm install v5.7.1 and see if the issue is fixed?

  4. peteringraham commented on Sep 27, 2016

    @peteringraham
    Author

    Looks like it worked. I guess this was a side-effect of sudo npm install -g when trying to fix unrelated errors earlier.

    nvm uninstall 5.7.1
    file is not writable: $NVM_DIR/versions/node/v5.7.1/bin/grunt
    Cannot uninstall, incorrect permissions on installation folder.
    This is usually caused by running `npm install -g` as root. Run the following commands as root to fix the permissions and then try again.
    
      chown -R pingraham "$NVM_DIR/versions/node/v5.7.1"
      chmod -R u+w "$NVM_DIR/versions/node/v5.7.1"
    

    After running those, uninstalling, and reinstalling, no error message, node -v returns 5.7.1.

    I'll re-open if something surprising happens later, but I think this is mostly fixed.

    Note that nvm ls now claims it's using "5.7.1" rather than "system", so maybe using the system version of node isn't really supported? OTOH, this might be too specific & weird a situation to bother having specific commentary on.

    Thanks again for your help.

  5. elimcjah commented on Aug 31, 2017

    @elimcjah

    @ljharb Thanks! nvm uninstall v5.7.1 && nvm install v5.7.1 worked for me.

  6. jedwards1211 commented on Dec 12, 2017

    @jedwards1211

    None of the fixes here seem to have worked for me, and I get this error regardless of which version I'm trying to switch to.

    However, if I merely run nvm use a second time, it succeeds. I wonder if that's why some of these fixes "worked" for other folks here? If I open a new terminal I get the error again the first time I run nvm use, and after that it's okay.

  7. ljharb commented on Dec 12, 2017

    @ljharb
    Member

    @jedwards1211 is there any chance you have something in your shell profile files that modifies the PATH after nvm is sourced? If so, a second nvm use would correct the PATH.

  8. 46 remaining items

  9. karlmacklin commented on May 5, 2020

    @karlmacklin

    nvm unalias default worked for me as well, thanks.

    I had this problem not when launching Ubuntu (in my WSL 1 env in Win10), but when opening tmux within it. Super annoying, those error messages should be removed since doing the fixes in them didn't help at all.

  10. hrasoa commented on Jun 18, 2020

    @hrasoa

    Just run into this issue, and here's what I did to fix it:

    1. remove node: brew uninstall node
    2. install desired version: nvm install 'lts/*'
    3. set the default version: nvm alias default 'lts/*'
    4. delete npm prefix: npm config delete prefix
    5. set prefix to the node version used with nvm: npm config set prefix $NVM_DIR/versions/node/v12.18.1
  11. ljharb commented on Jun 18, 2020

    @ljharb
    Member

    Setting the prefix like that is both unnecessary and will prevent nvm from being able to switch versions.

  12. hrasoa commented on Jun 18, 2020

    @hrasoa

    @ljharb I had no issue switching from 12.x to 14.x 😉

  13. ljharb commented on Jun 19, 2020

    @ljharb
    Member

    @hrasoa if in node 14, npm root -g points to node 12's npm, you will have issues. Global modules must not be shared across node versions.

  14. tahoemph commented on Jul 14, 2020

    @tahoemph

    The route that got me to this error was mixing installations of node based packages using nvm and brew. This can get a bit painful as installing the heroku tools or yarn will install their own version of node. I was able to resolve my issues by only ever using nvm. Big YMMV.

  15. tflx commented on Nov 10, 2020

    @tflx

    I had the same issue as @radum - renaming my user folder to not include uppercase letters fixed it.
    That really shouldn't be necessary IMO.

  16. ljharb commented on Nov 11, 2020

    @ljharb
    Member

    @tflx i agree - but did the casing of whoami and echo $HOME match? if not, fix that, as that's the issue.

  17. sbaraka commented on Nov 20, 2020

    @sbaraka

    none of these work for my raspberry pi 3 running raspberry OS

  18. ljharb commented on Nov 20, 2020

    @ljharb
    Member

    @sbaraka then please file a new issue and file out the entire issue template. Thanks!

  19. mklb commented on Jun 18, 2021

    @mklb
  20. ljharb commented on Jun 18, 2021

    @ljharb
  21. mklb commented on Jun 18, 2021

    @mklb

    Good point @ljharb - the better fix was deleting the version entry in ${HOME}/.npmrc. No idea how it got there..

  22. lucasrueda commented on Aug 17, 2021

    @lucasrueda

    In my case I had:

    • nvm as oh-my-zsh plugin
    • NVM_LAZY=1
    • NVM_AUTOLOAD=1

    I had to remove the NVM_LAZY variable from .zshrc and everything worked

  23. crisdosaygo commented on Nov 1, 2021

    @crisdosaygo

    If I want to run nvm in somewhere inside an npm script (or in the subprocess tree of one), then I do:

    #!/bin/bash
    
    unset npm_config_prefix
    
    source $HOME/.nvm/nvm.sh
    . $HOME/.profile
    
    version=v14.15.3 
    
    nvm install $version
    nvm use $version
    
    # rest of script that uses node version $version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS: Mac OSbugsOh no, something's broken :-(needs followupWe need some info or action from whoever filed this issue/PR.shell: bash/sh

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions