Yarn: "yarn global add" doesn't globally install packages if .yarn-cache was restored

Created on 17 Oct 2016  ·  13Comments  ·  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?
Bug

What is the current behavior?
If you restore .yarn-cache from another machine (e.g. on a CI system) that had a globally installed package, then running yarn global add <pkg> doesn't install the package on the new machine.

If the current behavior is a bug, please provide the steps to reproduce.
Set up a circle.yml file that tells CircleCI to cache ~/.yarn-cache. Run a build and then run it again (make sure in the "Restore cache" step that home/ubuntu/.yarn-cache is restored).

The second time around, even though yarn global add codecov runs successfully and says success Installed [email protected] with binaries: codecov, the codecov package is missing. It doesn't place anything in nvm's global node_modules folder nor the bin folder.

machine:
  pre:
    - mkdir ~/.yarn-cache
  node:
    version: 6

dependencies:
  cache_directories:
    - ~/.yarn-cache
  pre:
    - curl -o- -L https://yarnpkg.com/install.sh | bash
    - yarn global add codecov
  override:
    - yarn

test:
  pre:
    - yarn run lint
  override:
    - yarn test -- --coverage
  post:
    - codecov

What is the expected behavior?
yarn global add <pkg> should reinstall the package. As a workaround, using npm or yarn global remove <pkg> works fine.

Please mention your node.js, yarn and operating system version.
Node 6.8.1 installed with nvm 0.31.0
Yarn 0.15.1 installed via curl + bash
Ubuntu 12.04 on CircleCI

cat-bug triaged

Most helpful comment

More universal export (without username):
PATH="${HOME}/.config/yarn/global/node_modules/.bin${PATH:+:${PATH}}"; export PATH;

why so complicated?
Here this does the job equally well and universal …
export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin"

All 13 comments

I'm having the same issue, but with different circumstances. If I install a new version of node alongside an old version (using nvm), then yarn global add does not result in any packages being installed in the new bin. I assume that installing yarn in the new version of node results in the cache being "restored" from the old version of node?

^ Me too!

Same issue, using

  post:
    - bash <(curl -s https://codecov.io/bash)

is fast enouth (more than npm) and don't require to install any dependency

yeah we are also having this same issue

@andrewmclagan I had some issues like these after some debugging I realized that there were two versions of yarn. After that you must make sure that the bin folder is in the path variable —

export PATH="/usr/local/bin:/Users/andrew/.config/yarn/global/node_modules/.bin"

More universal export (without username):
PATH="${HOME}/.config/yarn/global/node_modules/.bin${PATH:+:${PATH}}"; export PATH;

@iryston where should i put this?

@IzaGz it depends on your OS and shell.
If you have *NIX & BASH put it in .bashrc or .bash_profile.
For ZSH put it in .zshrc or .zprofile.

More universal export (without username):
PATH="${HOME}/.config/yarn/global/node_modules/.bin${PATH:+:${PATH}}"; export PATH;

why so complicated?
Here this does the job equally well and universal …
export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin"

just out of curiosity, is there any reason we don't use the same path that npm uses? I was expecting yarn to be a drop in replacement (minus command names) for npm.

Isn't there a cleaner solution? I installed parcel globally and came up to this issue... The solutions above work, but checking out the global .bin folder of yarn there's way more there than I actually need. Following this solution added a bunch of binaries to my path without necessity.

workaround for windows:

%USERPROFILE%\AppData\Local\Yarn\bin

yarn add global gulp-cli
не устанавливает gulp-cli глобально, либо в ту же папку, либо в корень диска.

Was this page helpful?
0 / 5 - 0 ratings