yarn 1.2.1 not symlinking global binaries when used with nvm under linux/zsh

Created on 13 Oct 2017  路  22Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

its a regression bug in a feature, i guess? not entirely sure wheter yarn really is intended to work with nvm under linux, if it isn't, then this is a feature request :)

What is the current behavior?

yarn global add ... does not create links from the NVM_BIN directory to exectutable files in ~/.config/yarn/global/node_modules/*, which older versions seem to have done. hence i consider this to be a regression?

If the current behavior is a bug, please provide the steps to reproduce.

nvm install v8.7.0 && nvm alias default v8.7.0 && nvm use default
npm i -g npm yarn
yarn global add prettier

What is the expected behavior?

after above shell commands
~/.nvm/versions/node/v8.7.0/bin/ should contain a symlink prettier -> ../../../../../.config/yarn/global/node_modules/prettier/bin/prettier.js. (the former directory is stored in the environment variable NVM_BIN)

Please mention your node.js, yarn and operating system version.
node: v0.8.7
yarn: 1.2.1
OS: Linux 4.13.5-1-MANJARO #1 SMP PREEMPT Thu Oct 5 15:24:20 UTC 2017 x86_64 GNU/Linux
shell: zsh 5.4.2 (x86_64-unknown-linux-gnu)
nvm: 0.33.4

Most helpful comment

@dandv Try adding this line to .zshrc and source it...
```bash export PATH="$PATH:yarn global bin`"

All 22 comments

The same thing is happening on a mac. The issue started after upgrading from 1.1.0 -> 1.2.1.

Have you tried installing Yarn using Homebrew rather than npm? Installing via npm sometimes does strange things.

What do you get if you run yarn global bin?

Are you using workspaces? It's a known issue: https://github.com/yarnpkg/yarn/issues/4706

yarn global bin yields /home/<username>/.yarn/bin
npm version is 5.5.1

i'm assuming the Homebrew question was directed at ifiokjr, as i'm running linux. no workspaces, no other type of monorepo. i do have, however, some local dependencies wired up via yarn link.

On my Ubuntu I'm getting similar error installing globally ember-cli package:

```$ yarn global add ember-cli
yarn global v1.2.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
- ember
- 馃惞
Done in 7.16s.
$ ember
zsh: command not found: ember

For fixing it, I did the following patchy-way-sequence:

enter BASH world (get out of oh-my-zsh and zsh)

$ bash
$ yarn global remove ember-cli
$ yarn global add ember-cli

get back to oh-my-zsh

$ exit
$ ember

worked!!!!

```

@morhook That worked! I wonder what's up with zsh

My versions:

Ubuntu: 17.04
zsh: 5.2-5ubuntu1
nvm: 0.33.2
node: v8.0.0
npm: 5.4.2

@pedro-mass looks like a weird cache/startup/bootup problem (as after this first run from bash it seem to make the symlinks fine).

Previously I had yarn 1.2.0 and didn't have this problem if that helps as info too!

I have yarn v1.2.1 installed on macOS 10.13 via homebrew. I have node v8.8.1 installed via nvm.

npm bin -g outputs /Users/johng/.nvm/versions/node/v8.8.1/bin
yarn global bin outputs /usr/local/bin

When I run yarn global add @angular/cli, the ng command gets added to /usr/local/bin as a symlink to /Users/johng/.config/yarn/global/node_modules/@angular/cli/bin/ng instead of to /Users/johng/.nvm/versions/node/v8.8.1/bin/ng.

I had a similar issue with Yarn installed through Homebrew, I'm guessing it had something to do with permissions because the following fixed it:

yarn global remove $PACKAGE
yarn config set prefix "$HOME/.yarn"
yarn global add $PACKAGE

Previously yarn global bin gave me /usr/local/bin but no symlink was created there, once I changed it to a path inside my home directory it worked fine.

EDIT:

This happened with both Yarn 1.2.1 and 1.3.2 on two different Macs, one running 10.13 and one running 10.13.1 beta.

Note that my expectation is that yarn global bin would have the same value as npm bin -g. That way when I switch to a different version of node I don't have the old version's executables still sitting around behaving badly.

I also have this problem, and I can't find my global packages in the yarn global bin

I have upgraded yarn to 1.3.2 (erased installed version via rm -rf ~/.yarn and installed via apt repos) and it's happening again to me. More info on my setup:

$ npm bin -g
/home/cruz3/.nvm/versions/node/v8.0.0/bin
$ yarn global bin
/home/cruz3/.yarn/bin

I think it's not happening so similar as described by @wesm87 in my installation.

I've found another workaround on my setup (even weirder but with yarn 1.3.2-1):

# cleanup and install
$ sudo apt remove yarn && rm -rf ~/.yarn && sudo apt install yarn
# install via yarn
$ yarn global add ember-cli
$ ember
zsh: command not found: ember
$ yarn global remove ember-cli
$ yarn global add ember-cli
$ ember
# WORKS!

I meet the same problem with @morhook and also solved with the same method on MacOS/zsh.

Node: 6.11.5 (installed via Homebrew)
Yarn: 1.3.2 (installed via Homebrew)
OS: macOS High Sierra 10.13.1
Shell: zsh in iTerm2

I found the global binaries in ~/.config/yarn/global/node_modules/.bin , but my yarn global bin show /usr/local/bin and the same to npm -g bin .

When uninstalled package and installed again, it works.

Sometimes when I uninstalled packages, the yarn global binaries also was removed in /usr/local/bin , so I had to add export PATH="/usr/local/opt/yarn/bin:$PATH" in ~/.zshrc .

I have resolved this just by reinstall yarn.

None of the above workarounds worked for me (add/remove/add packages, reinstall yarn... nothing).

Using ubuntu xenial and nvm 0.33.6, the node version currently used by nvm apparently doesn't affect, as I've experienced this issues under versions 6, 7 & 8

@imzhengfei thank youuuu

@dandv Try adding this line to .zshrc and source it...
```bash export PATH="$PATH:yarn global bin`"

Add $HOME/.config/yarn/global/node_modules/.bin/`
in ~/.zshrc

This works for me.

export PATH="$HOME/.yarn/bin:/usr/local/bin/:$PATH:$HOME/.config/yarn/global/node_modules/.bin/"

I'm having the same issue. No matter what I try, anything installed with yarn global add ends up in the wrong place and is not in the PATH.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:        17.10
Codename:       artful
$ echo $0
/bin/bash
$ nvm --version
0.33.8
$ node --version
v9.7.1
$ npm --version
5.6.0
$ yarn --version
1.5.1
$ npm bin -g
/home/tjp/.nvm/versions/node/v9.7.1/bin
$ yarn global bin
/home/tjp/.yarn/bin

Have the same issue, bin points to /usr/local/bin

@rapcal's way worked for me. Absolutely the most flexible option among the discussed in this thread.

Was this page helpful?
0 / 5 - 0 ratings