问题
I'm working with Yarn v0.16.1. If I understand correctly (according to the documentation), yarn global add <package>
should be the equivalent of npm install -g <package>
. However, when I run the example in the docs (with create-react-app
), the command runs successfully but create-react-app
is then not available from the command line. Here's the output:
$ yarn global add create-react-app
$ yarn global v0.16.1
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Installed create-react-app@0.6.0 with binaries:
- create-react-app
✨ Done in 3.22s.
$ create-react-app --help
-bash: create-react-app: command not found
Doing a global install with npm has the expected result, and everything works. What am I missing with yarn?
回答1:
You should add export PATH="$PATH:$(yarn global bin)"
to your ~/.bash_profile
or whatever you use. It would solve the issue.
Depending on how you installed it, Yarn's global folder varies for some reason. You can follow this issue here.
回答2:
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
Confirm your global bin path
yarn global bin
I got: /home/username/.yarn/bin
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
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
restart your shell or start a new one
bash -l
orzsh
回答3:
In my case yarn global bin
wasn't working.
Try a brew reinstall yarn
if that's how you installed yarn
👍🏻
回答4:
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
回答5:
To reinstall run below.
brew install -g yarn
// Note:(updating homebrew) for Mac users.
brew reinstall yarn
// (if yarn is still not found)
来源:https://stackoverflow.com/questions/40317578/yarn-global-command-not-working