Issue
When a user is using yarn
to perform build tasks, it may appear that yarn
is reinstalling node modules even though the build is expected to be using the Heroku cache.
Resolution
Check if NODE_MODULES_CACHE
is true
. If it is, the build is using the Heroku build cache. This is cached from build to build to be reused.
If it is false
or blank, set it to true:
heroku config:set NODE_MODULES_CACHE=true -a APP_NAME
When NODE_MODULES_CACHE
is true
, the buildpack will copy the node modules from the app directory ($build_directory/node_modules
) to the Heroku cache at the end of the build. On the next build, the buildpack will restore those node modules to the app directory, then it will run yarn install
and use the yarn.lock
to resolve dependencies.
Monorepos
If there are multiple node_modules directories (for example, a directory for server
and a directory for ui
), the app will need to use cacheDirectories
to customize for multiple node modules cache directories.
Please read more about this in our Dev Center:
https://devcenter.heroku.com/articles/nodejs-support#custom-caching