DEV Community

Discussion on: How to cache node_modules in GitHub Actions with Yarn

Collapse
 
flydiverny profile image
Markus Maga

Recommend taking a look at github.com/bahmutov/npm-install :) tried to make this effortless!

Collapse
 
sangheestyle profile image
SangHee Kim

I tried bahmutov/npm-install and it took much longer to retrieve cache compared to that of actions/cache.

So, please keep in mind node_modules size when choose one. :)

Collapse
 
flydiverny profile image
Markus Maga

As far as I know bahmutov/npm-install uses the @actions/cache under the hood so the cache retrieval itself should be the same as github actions cache.
But the other steps might still take longer as it doesn't cache the node_modules, like this post suggest as an improvement. So if that's what you compared to I'd expect different results!

As also mentioned in the post the "official" recommendation is to not cache the node_modules folder itself, as that can potentially cause trouble in some scenarios. You can probably avoid those by putting for example the node version in your cache key or so.

github.com/actions/cache/blob/main...

Note: It is not recommended to cache node_modules, as it can break across Node versions and won't work with npm ci

That said I also wish it was a bit faster 😅