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

Where does yarn store global packages (lib not bin) #2049

Closed
Nikki1993 opened this issue Nov 27, 2016 · 20 comments
Closed

Where does yarn store global packages (lib not bin) #2049

Nikki1993 opened this issue Nov 27, 2016 · 20 comments

Comments

@Nikki1993
Copy link

Nikki1993 commented Nov 27, 2016

Hello everyone,

I am sorry if this question has been answered already, but I searched through google and github and couldn't find anything relevant. Where does yarn global add Installs packages? For instance, I have typescript installed through NPM and the tsserver is located in Users/kononnik/.nvm/versions/node/v7.2.0/lib/node_modules/typescript/lib but where is the node_modules packages for global npm packages installed through yarn?

@TheLudd
Copy link

TheLudd commented Nov 27, 2016

On linux they are stored in ~/.config/yarn/global

@msegado
Copy link

msegado commented Nov 28, 2016

The logic determining this is in src/constants.js; you can start at line 56 and work your way back from there. Currently it works out to:

  • %LOCALAPPDATA%/Yarn/config/global on Windows [edited; thanks @onemen!]
  • ~/.config/yarn/global on OSX and non-root Linux
  • /usr/local/share/.config/yarn/global on Linux if logged in as root

@onemen
Copy link

onemen commented Nov 28, 2016

on Windows is %LOCALAPPDATA%/Yarn/config/global

@Nikki1993
Copy link
Author

Thanks everyone :)

@ghost
Copy link

ghost commented Sep 2, 2017

is this documented on the website, docs or command line help?

@avegancafe
Copy link

Adding a message to say where the package is installed would be exceedingly useful

@HaleTom
Copy link

HaleTom commented Oct 19, 2017

Ask yarn itself to tell you (as config prefix may set a different location):

yarn global dir

@ghost
Copy link

ghost commented Oct 19, 2017

@HaleTom awesome thanks!

is that documented somewhere on the website or docs? seems non-obvious and too useful not to call out somewhere else

@HaleTom
Copy link

HaleTom commented Oct 19, 2017

@omouse
I documented it at Where does yarn keep global packages?, but you could help out by having it officially documented (it is missing from here) either directly or by raising an issue.

@bchenSyd
Copy link

bchenSyd commented Apr 25, 2018

the real problem is yarn global dir is not part of node search path by default.
e.g. yarn global add semver , and node -e 'require('semver)' throws 'module not found' error

only npm i -g ones are included. Shell this be documented? what is the official way to add yarn global dir to node search path?

@bchenSyd
Copy link

require(X) from module at path Y

LOAD_NODE_MODULES(X, dirname(Y))


LOAD_NODE_MODULES(X, START)
1. let DIRS=NODE_MODULES_PATHS(START)
2. for each DIR in DIRS:
   a. LOAD_AS_FILE(DIR/X)
   b. LOAD_AS_DIRECTORY(DIR/X)



NODE_MODULES_PATHS(START)
1. let PARTS = path split(START)
2. let I = count of PARTS - 1
3. let DIRS = []
4. while I >= 0,
   a. if PARTS[I] = "node_modules" CONTINUE
   b. DIR = path join(PARTS[0 .. I] + "node_modules")
   c. DIRS = DIRS + DIR
   d. let I = I - 1
5. return DIRS

seems npm i -g modules aren't in node search path either.

@khalid-elabbadi
Copy link

can we change this location ?

@gera2ld
Copy link

gera2ld commented May 9, 2018

Is there a way to get this path dynamically? It seems that yarn v1.5.1+ has changed the path on Windows.

@toupeira
Copy link

@gera2ld as explained above you can use yarn global dir to get the location, and also yarn global bin to get the binary path (~/.yarn/bin on Linux).

@khalid-elabbadi see yarn config current

@bochen2014 you can add the location to $NODE_PATH

@fousu
Copy link

fousu commented Feb 22, 2019

@HaleTom ,Thanks.

@farzadso
Copy link

@toupeira This is the answer I was looking for since I was working with various Docker images that had different configs.

@AlecRust
Copy link

So to be clear, if you use NVM like the original poster, you should use npm instead of yarn to install global packages? As Yarn does not install them in the appropriate NVM path for that Node version, like npm does?

@farzadso
Copy link

@AlecRust I guess that's the case. That's kind of my question too.

@AlecRust
Copy link

@farzadso I'm fairly confident after some investigation.

brew install yarn installs a Homebrew Node dependency, so /usr/local/yarn and /usr/local/node which a lot of things will use by default. This is bad if you use NVM and want both your Node and Yarn scoped to the correct NVM Node version.

After brew uninstall yarn && brew uninstall node && brew list to check I have no Homebrew Node or Homebrew Yarn installed, some things started failing for me. Shell scripts that depended on Node started to fail as /usr/local/node no longer existed, and my Husky pre-commit hooks started failing because no yarn was available.

In both these cases I now simply source NVM before calling binaries such as yarn. Husky has docs on this. Im quite happy with my NVM/Node/Yarn/npm setup now, all in my dotfiles if interested.

@farzadso
Copy link

@AlecRust I tested it and can confirm.

callmeteus added a commit to callmeteus/nayr that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests