VOOZH about

URL: https://github.com/orgs/community/discussions/200314

⇱ GitHub Actions cache not working consistently Β· community Β· Discussion #200314 Β· GitHub


Skip to content

πŸ‘ @community
GitHub Community

GitHub Actions cache not working consistently #200314

Closed Answered by rehuux
zaidonly asked this question in Code Security

πŸ‘ Image
zaidonly

Answered by rehuux

I faced this exact issue a few weeks ago. Here are the most common reasons and fixes:

  1. Check if cache is actually being restored

First, look at your workflow logs. Do you see Cache restored from key or Cache not found? If it says Cache not found, your key isn't matching.

Fix: Make sure package-lock.json exists and is being committed. If it's missing, hashFiles('**/package-lock.json') returns empty and cache misses every time.

  1. Don't cache node_modules directly

The official docs actually recommend against caching node_modules. It can cause issues with Node version mismatches and npm ci.

Better approach: Cache ~/.npm instead:

- name: Cache npm dependencies
 uses: actions/cache@v4
 with:…

Replies: 3 comments

πŸ‘ Image
github-actions[bot]
Bot

0 replies
0 replies
Answer selected by zaidonly

πŸ‘ Image
zaidonly
Author

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.