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?
On linux they are stored in ~/.config/yarn/global
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 rooton Windows is %LOCALAPPDATA%/Yarn/config/global
Thanks everyone :)
is this documented on the website, docs or command line help?
Adding a message to say where the package is installed would be exceedingly useful
Ask yarn itself to tell you (as config prefix
may set a different location):
yarn global dir
@HaleTom awesome thanks!
is that documented somewhere on the website or docs? seems non-obvious and too useful not to call out somewhere else
@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.
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?
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.
can we change this location ?
Is there a way to get this path dynamically? It seems that yarn v1.5.1+ has changed the path on Windows.
@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
@HaleTom ,Thanks.
@toupeira This is the answer I was looking for since I was working with various Docker images that had different configs.
Most helpful comment
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