Do you want to request a _feature_ or report a _bug_?
Bug/Feature
What is the current behavior?
Yarn points to a dynamic directory for global binaries (e.g /usr/local/Cellar/node/6.9.1/bin and 6.9.1 changes frequently).
If the current behavior is a bug, please provide the steps to reproduce.
Installing node and yarn with Homebrew results in this inability/redundancy to access/install binaries.
What is the expected behavior?
Yarn should place global binaries in a static folder (e.g ~/.yarn/bin), which is most likely already in people $PATH variable, and it already exists.
Please mention your node.js, yarn and operating system version.
OS: MacOS 10.12.1 Beta
❯ node -v
v6.9.1
❯ yarn --version
0.16.1
❯ brew -v
Homebrew 1.0.8
Homebrew/homebrew-core (git revision 94948; last commit 2016-10-23)
@adamSiwiec Based on how/why NPM does this currently, imo this shouldn't necessarily be added to yarn.
Currently, NPM does not put global binaries in a static folder, or rather, a folder that stays the same regardless of node version. This is, as far as I can tell, by design – if you changed the node version and the installed global binary stayed the same, but the installed global binary was incompatible with the new node version (for example, a global binary that only works with 0.10/0.12 and you change your node version to 6.0), the global binary could cease to work, and would likely throw silent or unhelpful errors.
tl;dr the reason the global binaries are linked to a dynamic folder is to ensure node version compatibility and is by design.
I think the big issue here is when you install something with the global scope, and that binary can't be available globally because that PATH isn't automatically exported.
i.e. You install grunt
-> yarn global add grunt-cli
The binary will be added to the folder "/usr/local/Cellar/node/6.9.1/bin/" and to call it will be required add that folder manually to the PATH var or call it directly with the path:
/usr/local/Cellar/node/6.9.1/bin/grunt
Obviously are something wrong there, because is supposed that yarn global add <package>should be the same as npm install -g <package>
I added the following line to my .bashrc and everything is working fine:
export PATH="$HOME/.yarn-config/global/node_modules/.bin:$PATH"
Note: I installed both node and yarn via homebrew.
_EDIT: New solution for yarn nightlies posted below_.
@cwonrails seems not to work anymore with new versions since ".yarn-config" not exists see #1321
The only way for now is get back go 0.16.1
I'm seeing it still working with 0.17.6, but I can confirm that 0.16.1 also works.
suggestion: yarn should install global packages in a directory that most people already have in its path, like npm does.
it doesn't even tell where the package is being installed, so you have to track this bug to see the fix and add .yarn-config to the path manually
@marcosfede +1
New two-step solution for those running the yarn nightlies:
(1) I have a ~/shell-scripts folder where I put upgrade-yarn.sh. Here's the script, which I run with cd ~/shell-scripts && ./upgrade-yarn.sh (aliased to yu):
#!/bin/sh
rm -rf install.sh
wget https://yarnpkg.com/install.sh
chmod +x install.sh
./install.sh --nightly
rm -rf install.sh
(2) After running the script, I make sure the following two lines are located at the bottom of my .bashrc (should work in .zshrc, .profile etc.):
# Enable yarn nightly
export PATH="$HOME/.yarn/bin:$PATH"
# Enable yarn nightly global binaries
export PATH="$HOME/.config/yarn/global/node_modules/.bin:$PATH"
All global binaries are now available! (currently running version 0.18.0-20161124.1454.)
_Extra steps for testing the new install_
I then run exec $SHELL -l to reload the default shell, run yarn global add create-react-app (or whatever) and check the output of yarn global ls. Here's the current output from my terminal:
yarn global ls
yarn global v0.18.0-20161124.1454
warning No license field
info [email protected] has binaries:
- create-react-app
info [email protected] has binaries:
- diff-so-fancy
- diff-highlight
info [email protected] has binaries:
- http-server
- hs
info [email protected] has binaries:
- lerna
info [email protected] has binaries:
- stylefmt
info [email protected] has binaries:
- stylelint
info [email protected] has binaries:
- tsc
- tsserver
✨ Done in 1.17s.
Here's the output from which http-server:
/Users/christopherwatson/.config/yarn/global/node_modules/.bin/http-server
Hope this proves helpful!
Duplicate: https://github.com/yarnpkg/yarn/issues/2064
@bestander we can close this because it is a duplicated. @OmgImAlexis you are awesome O.o
Most helpful comment
I added the following line to my
.bashrcand everything is working fine:export PATH="$HOME/.yarn-config/global/node_modules/.bin:$PATH"Note: I installed both node and yarn via homebrew.
_EDIT: New solution for yarn nightlies posted below_.