node.jsdockerherokupnpmcorepack

After Heroku restart: pnpm: Error: Cannot find matching keyid


My Heroku-hosted node app stopped working this morning at 6am.
In the Heroku console I found a message "Dyno restart" at that time. At the same time, memory usage dropped to 0. Apparently the app did not recover after the restart.

I attempted to just re-run my Github Action deploy workflow to redeploy the app and trigger a restart.
I get the following error:

#11 [prod-deps 1/1] RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
#11 0.558 /usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:21535
#11 0.558   if (key == null || signature == null) throw new Error(`Cannot find matching keyid: ${JSON.stringify({ signatures, keys })}`);
#11 0.558                                               ^
#11 0.558 
#11 0.558 Error: Cannot find matching keyid: {"signatures":[{"sig":"MEQCI...

Apparently something related to pnpm and corepack.

I found a quick fix by changing my Dockerfile:

FROM node:20-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# RUN corepack enable                                  # <= removed this
RUN corepack disable && npm install -g pnpm@latest     # <= added this
COPY . /app
WORKDIR /app
# ...

The deployment now works again, the app is back up.

However I don't understand the underlying problem:


Solution

  • This answer from Vercel's post worked for me. If you're on Node 18+, you can just install the latest version of corepack before enabling it.

    steps:
      - name: Use Latest Corepack
        run: |
          echo "Before: corepack version => $(corepack --version || echo 'not installed')"
          npm install -g corepack@latest
          echo "After : corepack version => $(corepack --version)"
          corepack enable
          pnpm --version
    

    Also, if you're on Node 16, they say corepack v20 still supports it.