nvm is not compatible with the npm config “prefix” option:

前端 未结 16 1393
梦毁少年i
梦毁少年i 2020-12-07 06:47

I am trying to run another NodeJS version with nvm but getting this error:

$ nvm use v4.2.4

nvm is not compatible with the npm config \"prefix\         


        
相关标签:
16条回答
  • 2020-12-07 07:23

    It might be the problem if you have your home directory mounted somewhere, due nvm does not work properly with symlinks. Because I don't care where is my $NVM_DIR located I run this and all works fine:

    $ mv ~/.nvm /tmp/
    $ export NVM_DIR="/tmp/.nvm"
    $ nvm use --delete-prefix v6.9.1
    
    0 讨论(0)
  • 2020-12-07 07:24

    Delete and Reset the prefix

    $ npm config delete prefix 
    $ npm config set prefix $NVM_DIR/versions/node/v6.11.1
    

    Note: Change the version number with the one indicated in the error message.

    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 v6.11.1 --silent" to unset it.


    Credits to @gabfiocchi on Github - "You need to overwrite nvm prefix"

    0 讨论(0)
  • 2020-12-07 07:26

    Let me describe my situation.

    First, check the current config

    $ nvm use --delete-prefix v10.7.0
    $ npm config list
    

    Then, I found the error config in output:

    ; project config /mnt/c/Users/paul/.npmrc
    prefix = "/mnt/c/Users/paul/C:\\Program Files\\nodejs"
    

    So, I deleted the C:\\Program Files\\nodejs in /mnt/c/Users/paul/.npmrc.

    0 讨论(0)
  • 2020-12-07 07:28

    This may be a conflict with your local installation of Node (if you had it installed via another way than NVM in the past). You should delete this instance of node:

    1. remove node_modules sudo rm -rf /usr/local/lib/node_modules
    2. remove node sudo rm /usr/local/bin/node
    3. remove node link cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm

    After you cant install nvm

    0 讨论(0)
  • 2020-12-07 07:31

    This error can occur when your NVM installation folder path has a Symbolic Link.

    Explanation

    The default installation path of NVM is: $HOME/.nvm but your home folder could be a symbolic link for another drive, like my case.

    Example, my home folder is a Symbolic Link to aother drive:

    /home/myuser -> /bigdrive/myuser

    This cause the prefix problem.

    Solution

    On your startup script (.bashrc or .zshrc or other), change the NVM folder to the direct path.

    Ex: NVM_DIR="/bigdrive/myuser/.nvm".

    .bashrc

    export NVM_DIR="/bigdrive/myuser/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
    
    0 讨论(0)
  • 2020-12-07 07:32

    I had the same problem and it was really annoying each time with the terminal. I run the command to the terminal and it was fixed

    For those try to remove nvm from brew

    it may not be enough to just brew uninstall nvm

    if you see npm prefix is still /usr/local, run this command

    sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

    0 讨论(0)
提交回复
热议问题