Even though the
cache-folder option is deprecated, it’s also completely ignored by yarn 2/3, so anyone can set up the env variables that suits their needs. The PR you mentioned won’t fix the issue that you’d have to set an env in your netlify config to get it working.
We use the
YARN_CACHE_FOLDER variable and it has been very useful. Installs the whole project in 15s instead of 5mn (when only the node_modules are cached).
All in all, these are the env variables that I find relevant for all things yarn2-related on Netlify:
# Yarn classic version used to bootstrap. Default for @netlify/build < 4 is 1.17, which isn't enough
YARN_VERSION = "1.22.5"
# Only needed in case Yarn can't be detected in your base folder
NETLIFY_USE_YARN = "true"
# Feature flag to cache all the node_modules folders of the workspaces detected by `YARN_IGNORE_PATH=1 yarn workspaces --json info`
# Only use this if you have `workspaces` in your package.json
NETLIFY_YARN_WORKSPACES = "true"
# Equivalent to setting `cacheFolder` in your .yarnrc.yml
YARN_CACHE_FOLDER = "/opt/buildhome/.yarn_cache"
Alternatively, as mentioned in the PR you linked to @camjackson, you can also set yarn’s global folder to the location cached by netlify and instruct yarn to use this as the cache, i.e. instead of
YARN_CACHE_FOLDER = "/opt/buildhome/.yarn_cache", doing:
YARN_GLOBAL_FOLDER = "/opt/buildhome/.yarn_cache"
YAN_ENABLE_GLOBAL_CACHE = 1
@PizzaFox does this help?