How a Lockfile-Only Cache Key Shipped a Node 18 Native Module Into a Node 20 Image and Crash-Looped Every Pod
← Back
November 26, 2026CI/CD8 min read

How a Lockfile-Only Cache Key Shipped a Node 18 Native Module Into a Node 20 Image and Crash-Looped Every Pod

Published November 26, 20268 min read

11:04 UTC. Argo CD shows the billing-api rollout stuck at 1 of 6 pods ready. The new pods are in CrashLoopBackOff, restart count 7 and rising. Staging was green forty minutes ago.


the scramble

Meera is on call. She pastes the first line of the pod log into the incident channel:

Error: The module '/app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 108. This version of Node.js requires NODE_MODULE_VERSION 115. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). at process.func [as dlopen] (node:internal/process/process_methods:...) code: 'ERR_DLOPEN_FAILED'

108 is Node 18, 115 is Node 20. The only change in the release was a one-line Dockerfile edit, FROM node:18-slim to FROM node:20-slim, part of the runtime upgrade we had planned for the quarter. The rollout strategy kept the five old pods serving, so customers saw nothing. That bought us time. It did not buy an answer.

First theory, from Arjun: the base image tag is wrong and something is still pulling Node 18. We ran docker run --rm billing-api:7f3c1e2 node -v and got v20.11.1. The image runs Node 20. The module inside it was built for 18. So the question was how a Node 20 image ended up with Node 18 binaries.

the hunt

Second theory: the Dockerfile runs npm ci in the build stage, so maybe the build stage still used a cached Node 18 layer. Docker's layer cache keys on the instruction text and the parent layer, and the parent layer changed with the FROM line. We rebuilt locally with --no-cache and the image started fine. That ruled out the registry and the Dockerfile's own layers, but the CI image still failed. So CI was doing something the local build was not.

Third theory: a bad bcrypt release. We checked npm ls bcrypt in both builds. Same version, 5.1.1, same integrity hash in package-lock.json. Dead end, and a useful one, since it meant the lockfile was identical between the good and bad builds.

I opened the workflow file. The pipeline does not run npm ci inside Docker. A previous optimisation, from about a year ago, installs dependencies on the runner with actions/cache and then does COPY node_modules ./node_modules in the Dockerfile to save ninety seconds of build time.

# .github/workflows/build.yml (before) - uses: actions/setup-node@v4 with: node-version: 20 - uses: actions/cache@v4 with: path: node_modules key: deps-${{ hashFiles('package-lock.json') }} - run: npm ci --ignore-scripts=false if: steps.cache.outputs.cache-hit != 'true'

The cache key is the hash of package-lock.json and nothing else. The lockfile did not change in this release, so the key matched an entry written on the last day the runner used Node 18. The step restored a node_modules directory with bcrypt_lib.node compiled for ABI 108, skipped npm ci, and the Dockerfile copied it into a Node 20 image.

the find

Native addons are compiled at install time against the Node headers that are present. A cache key that ignores the Node version, the CPU architecture and the OS treats node_modules as plain data. With bcrypt, sharp or better-sqlite3 in the tree, it is machine code for one specific runtime.

Why did staging pass? Staging deploys from a different workflow that runs npm ci inside the image build, so it never touched the cache. Only the production workflow used the shortcut. We confirmed by listing the caches:

$ gh cache list --key deps- --limit 5 deps-9a41c7e0... 412 MB created 2026-11-19 last used 2026-11-26 deps-1be07d33... 409 MB created 2026-10-30 last used 2026-11-19 $ gh run view 9921340188 --log | grep -i "cache" Cache restored successfully Cache restored from key: deps-9a41c7e0...

The "Cache restored successfully" line is the whole incident. The step reported a hit, the install was skipped, and nothing in the job log suggested anything was off. The build was green for 11 minutes before Argo noticed the pods.

the fix

Immediate: roll back the Argo application to the previous image and delete the stale cache so the next run rebuilt it.

argocd app rollback billing-api gh cache delete deps-9a41c7e0...

Durable: put the runtime into the key. Anything that changes what npm ci would produce has to be part of the key, which means the Node version, the OS and the architecture. We also stopped copying node_modules from the runner at all for the production image, since the ninety seconds were not worth the failure mode.

# .github/workflows/build.yml (after) - uses: actions/setup-node@v4 id: node with: node-version-file: .nvmrc - uses: actions/cache@v4 id: cache with: path: ~/.npm key: npm-${{ runner.os }}-${{ runner.arch }}-node${{ steps.node.outputs.node-version }}-${{ hashFiles('package-lock.json') }} restore-keys: | npm-${{ runner.os }}-${{ runner.arch }}-node${{ steps.node.outputs.node-version }}- # Dockerfile FROM node:20-slim AS deps WORKDIR /app COPY package.json package-lock.json ./ RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev

Caching ~/.npm rather than node_modules keeps the download savings, and npm ci still compiles native modules against whatever Node is actually in the image. We also added a smoke step to the pipeline that runs the built image before pushing it:

- name: Smoke test image run: | docker run --rm "$IMAGE" node -e "require('bcrypt'); require('sharp'); console.log('native ok')"

the aftermath

Timeline: deploy at 10:53, first crash at 10:55, page at 11:04, rollback at 11:31, healthy at 11:34. About 41 minutes of a stuck rollout and zero customer-facing errors, because the old pods kept serving. The real cost was a blocked release train. Four other merges queued behind the broken one, and the Node 20 upgrade slipped two days.

  • The smoke test would have failed the build at 10:52, a minute before the image was pushed.
  • Staging and production now use the same Dockerfile path. The divergence between them is what hid the problem for a week of Node 20 testing.
  • The runbook for a crash loop right after a runtime bump now starts with grep NODE_MODULE_VERSION on the pod logs.
  • Any workflow that caches node_modules directly now fails a lint check in the repo's workflow review checklist.

A lockfile says which packages to install. It says nothing about what they were compiled against, and a cache key built only from it will miss a runtime bump every time. I had read that workflow a dozen times and never noticed.

Share this
← All Posts8 min read