Skip to content
shiporbreak

No streak yet

Sign in

November 14, 2026 路 #59

GitHub ActionsMediumOpen write-up

The cache that never refreshed

Months after a dependency upgrade, CI still restores the old node_modules and tests pass locally but fail in CI. Which line is wrong?

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules
      - run: npm install
      - run: npm test

Next puzzle in UTC

One try. The first answer sticks.

How to fix it

Cache entries are immutable and an exact key hit skips saving. The first node_modules ever cached is restored forever. Put the lockfile hash in the key.

actions/cache saves only when the key missed. With a constant key, the first run saves node_modules and every later run hits it. npm install then patches that old tree in place, which can leave stale or extra packages that differ from a clean install. The cache never updates, no matter how often the lockfile changes.

Fix

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci

setup-node caches ~/.npm with a key derived from package-lock.json, and npm ci builds a clean node_modules from the lockfile. If you cache manually, use key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}.

Sponsor this spot

Put your tool on the puzzle
One labeled card, in front of engineers who show up every day from YouTube, TikTok, and Instagram.