Skip to content

@clerk/fastify: silent peer-dep warning when host is on Fastify 4 leads to an unclear FST_ERR_PLUGIN_VERSION_MISMATCH at registration time #8844

@h2m6jcm94s-eng

Description

@h2m6jcm94s-eng

Package

`@clerk/fastify`

Current behaviour

`@clerk/fastify@^2` declares `peerDependencies.fastify` as `>=5`. When a host application still on Fastify 4 LTS installs `@clerk/fastify`, pnpm/npm prints a peer-dep warning, but the install otherwise succeeds.

The mismatch only surfaces at plugin-registration time, where `fastify-plugin` throws `FST_ERR_PLUGIN_VERSION_MISMATCH`. That error correctly identifies the mismatch but does not tell the user what to do — there is no mention of:

  • whether to upgrade Fastify, or
  • whether a `@clerk/fastify` version line that still supports Fastify 4 exists (it does — `@clerk/fastify@^1`).

Why this matters

Fastify 4 is still on LTS, and many production apps haven't migrated. The install-time peer warning is easy to miss when it shows up next to 10+ other peer-dep warnings during `pnpm install` / `npm install` (I hit this firsthand while bootstrapping a Fastify 4 app — by the time I got to `server.register(clerkPlugin)`, I had no recollection of the warning, and the stock error left me unsure whether to upgrade Fastify or downgrade `@clerk/fastify`).

Reproduction

```bash
mkdir clerk-fastify-4-repro && cd $_
npm init -y
npm install fastify@4 @clerk/fastify@latest
```

```js
// index.mjs
import Fastify from 'fastify';
import { clerkPlugin } from '@clerk/fastify';

const app = Fastify();
await app.register(clerkPlugin);
```

`node index.mjs` throws `FST_ERR_PLUGIN_VERSION_MISMATCH` mentioning `expected '5.x' fastify version`. No mention of `@clerk/fastify@^1` as a path forward.

Proposed fix

Throw a Clerk-branded error at registration time that:

  1. States the requirement (`fastify@>=5`) and the found version.
  2. Lists both resolution paths: upgrade Fastify, or pin `@clerk/fastify@^1` to stay on Fastify 4 LTS.
  3. Optionally — mention the requirement in the package README's Prerequisites section so it's visible before users hit registration.

PR #8843 implements this.

Environment

  • `@clerk/fastify` `3.1.36`
  • `fastify` `4.28.0`
  • Node `24.12.0`
  • pnpm `10.33`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions