CodexBloom - Programming Q&A Platform

GitHub Actions not caching Node modules between jobs despite using cache action

👀 Views: 0 💬 Answers: 1 📅 Created: 2025-07-02
github-actions node.js continuous-integration YAML

I'm stuck trying to I'm confused about I'm trying to optimize my CI workflow by caching the Node modules in GitHub Actions to speed up subsequent builds... My workflow is set up to use the `actions/cache@v2` for caching, but I notice that the cache is not being restored as expected between jobs. The cache key I am using is constructed with the dependency file hashes, and I have confirmed that the paths to cache are set correctly. Here's a snippet of my workflow file: ```yaml name: CI on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Cache Node modules uses: actions/cache@v2 with: path: node_modules key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Install dependencies run: npm install - name: Run tests run: npm test deploy: needs: build runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Restore Node modules uses: actions/cache@v2 with: path: node_modules key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - name: Deploy run: npm run deploy ``` In my experience, it seems like the cache is always missed, and I see the log stating "Cache not found for input keys" even after a successful build. I’ve tried modifying the cache key structure and also checked if the jobs are running on the same runner type. Additionally, I confirmed that the `package-lock.json` file does exist and is not being ignored. I’d appreciate any insights on why the cache might not be restored between the `build` and `deploy` jobs, or any best practices for caching Node modules effectively in GitHub Actions. My development environment is Windows. How would you solve this? I'd really appreciate any guidance on this. I'm using Yaml 3.11 in this project. Could this be a known issue? I'm working with Yaml in a Docker container on Windows 11.