Why does yarn create a ".yarn/cache" directory when using node-modules
?
My .yarnrc.yml
is:
nodeLinker: node-modules
Why does yarn create a ".yarn/cache" directory when using node-modules
?
My .yarnrc.yml
is:
nodeLinker: node-modules
node-modules
linker doesn't mean it's bound to node_modules
path (hyphen vs underline) but chooses an algorithm of how to install packages as far as I've understood.
Using e.g. 'pnp' instead of 'node-linker', then you don't need the node_modules
at all.
Yarn generates a .pnp.cjs
file:
{
"scripts": {
"start": "node ./server.js",
"test": "jest"
}
}
This approach is called Plug & Play I assume because it speeds up the installation process dramatically.
All this and more found: https://yarnpkg.com/features/pnp
I'm using yarn
or its alias yarn install
relatively often.
Yarn will check its cache for already downloaded packages and install them directly from there, which is much faster than downloading them from the registry.
You find a link at the bottom to read all the benefits like:
The offline cache is a feature that allows Yarn to work just fine even should the network go down for any reason - whether it's because your employer didn't pay the utility bill or because the place where your packages are hosted becomes unavailable. It's also a critical part of Zero-Installs and doesn't store more than a single file for each package - making it suitable for being stored within a repository, as we actually do in the Yarn repository itself.
There are additional benefits in separating the cache from node_modules
:
node_modules
but share the cache, in general I don't like to share the cache, but Yarn's cache is pretty strong doing so if you really want it.yarnrc.yml
file to either use enableGlobalCache
or set a specific path setting cacheFolder
Those are just examples.
Try out yarn help cache
to see yourself what you can do with your cache.
Where I got some of the infos: