π @community
GitHub Community
GitHub Actions cache not working consistently #200314
Β·
3 comments
Answered by
rehuux
I faced this exact issue a few weeks ago. Here are the most common reasons and fixes:
- 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.
- 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:β¦
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Category
Code Security
