Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn points to global binaries in a dynamic folder. #1389

Closed
adamsiwiec opened this issue Oct 24, 2016 · 10 comments
Closed

Yarn points to global binaries in a dynamic folder. #1389

adamsiwiec opened this issue Oct 24, 2016 · 10 comments
Labels

Comments

@adamsiwiec
Copy link

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)
@acburdine
Copy link

@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.

@chespinoza
Copy link

chespinoza commented Oct 24, 2016

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>

@cwonrails
Copy link

cwonrails commented Oct 24, 2016

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.

@DavidBabel
Copy link

@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

@aramk
Copy link

aramk commented Nov 21, 2016

I'm seeing it still working with 0.17.6, but I can confirm that 0.16.1 also works.

@marcosfede
Copy link

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

@DavidBabel
Copy link

@marcosfede +1

@cwonrails
Copy link

cwonrails commented Nov 24, 2016

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!

@OmgImAlexis
Copy link

Duplicate: #2064

@voxsim
Copy link
Contributor

voxsim commented Apr 28, 2017

@bestander we can close this because it is a duplicated. @OmgImAlexis you are awesome O.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests