Yarn global command not working

后端 未结 9 1915
孤独总比滥情好
孤独总比滥情好 2020-12-12 13:07

I\'m working with Yarn v0.16.1. If I understand correctly (according to the documentation), yarn global add should be the equivalent of np

相关标签:
9条回答
  • 2020-12-12 13:46

    On Ubuntu, I fixed by installing the package like this:

    sudo yarn global add <package> --prefix /usr/local
    
    0 讨论(0)
  • 2020-12-12 13:47

    Ran into this issue but on a Windows system. All I had to do was add the yarn global bin to the PATH variable.

    setx path "%path%;c:\users\YOURUSERNAME\appdata\local\yarn\bin"
    

    Remember to change YOURUSERNAME to your account username.

    You can check where your global bin is by running

    yarn global bin
    

    And please don't forget to restart the CMD window that you're working on. Happy coding!

    0 讨论(0)
  • 2020-12-12 13:48

    Update Dec 2018

    Just updating the path didn't work for me. I had to also set the yarn prefix.

    • Ubuntu 18.04.1 LTS (bionic)
    • yarn 1.12.3
    • npm v3.5.2
    • node v8.10.0
    • zsh 5.4.2

    Steps

    1. Confirm your global bin path

      yarn global bin
      

    I got: /home/username/.yarn/bin

    1. set yarn prefix:

      make sure your yarn prefix is the parent directory of your bin directory. You can confirm by running

      yarn config get prefix
      

      when I ran this, my prefix was empty, so I set it:

      yarn config set prefix ~/.yarn
      
    2. add the following to ~/.bash_profile or ~/.bashrc

      export PATH="$PATH:`yarn global bin`"
      

      for zsh users, be sure to add this line to ~/.zshrc

    3. restart your shell or start a new one

      bash -l or zsh

    0 讨论(0)
  • 2020-12-12 13:48

    When switching from bash to zsh, I got the same error, it worked for me:

    in your .zshrc 
    
    # NVM Stuff
    export NVM_DIR="$HOME/.nvm"
    . "$(brew --prefix nvm)/nvm.sh"
    
    # YVM Stuff
    export YVM_DIR="$HOME/.yvm"
    . "$(brew --prefix yvm)/yvm.sh"
    

    As I understand it, my mistake arose due to the lack of access to version managers

    0 讨论(0)
  • 2020-12-12 13:50

    Here's the process I used on Mac OSX El Capitan.

    1. Try to install yarn (I used the Curl command) if you have it already. This will bring up if its already installed and will give you the current directory where it exists.

    Like this:

    curl -o- -L https://yarnpkg.com/install.sh | bash
    

    It will display something like this:

    Installing Yarn!
    > /Users/{Your Username}/.yarn already exists, possibly from a past Yarn install.
    > Remove it (rm -rf /Users/{Your Username}/.yarn) and run this script again.
    

    Do not remove it. Move on to step 2.

    1. Copy the directory listed above. Open your profile. I'm using zsh. So mine was ~/.zshrc. You can find yours and more info here.

    2. Copy the following (replacing your directory and username details as necessary, the one you got from the installation error message).

      alias yarn="/Users/{Your Username}/.yarn/bin/yarn"

    1. Try to run yarn version to check if its working. If it is, you should see a version number displayed in your terminal.

    That's it, and what worked for me.

    0 讨论(0)
  • 2020-12-12 13:53

    In my case yarn global bin wasn't working.

    Try a brew reinstall yarn if that's how you installed yarn

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