[v8] @prisma/orm-postgres pins pg and @types/pg exactly in dependencies, so a pg.Pool passed via pg: must match them to the patch
Package and version
@prisma/orm-postgres 8.0.0-rc.23 (with @prisma/orm-target-postgres 8.0.0-rc.23)
What happened?
@prisma/orm-postgres and @prisma/orm-target-postgres declare "pg": "8.22.0" and "@types/pg": "8.20.4" as exact versions in dependencies. The postgres() façade accepts an application's own pool, pg?: Pool | Client in runtime.d.mts, typed from that bundled copy. The docs recommend this path for pool tuning ("construct the pg.Pool yourself and pass it via pg:").
As a result, the application must use exactly the same pg and @types/pg:
- With
@types/pg8.21.0, the types that describe pg 8.22 (they addClientBase.getTransactionStatus), the application'sPoolis not assignable to Prisma's, andpnpm why @types/pgshows two copies (TS2375, below). - The application can't take a
pgpatch release (for example a security fix) before Prisma does without getting a second runtime copy ofpg.
What did you expect to happen?
pg and @types/pg declared as peerDependencies with a range (for example "pg": "^8.20.0", optional @types/pg), the way libraries that accept a user-supplied driver do. Alternatively, a structural type for the pg: option. The runtime already checks the pool by shape (isPgPool), not by class identity, so only the types and the install tree need the change.
Minimal reproduction
package.json:
{
"type": "module",
"dependencies": { "@prisma/orm-postgres": "8.0.0-rc.23", "pg": "8.22.0" },
"devDependencies": { "@types/pg": "8.21.0", "typescript": "7.0.2" }
}
index.ts:
import postgres from '@prisma/orm-postgres/runtime';
import { Pool } from 'pg';
// An application's own pool, as the docs suggest: here a subclass that sets session state on checkout.
class AppPool extends Pool {}
declare const contract: Parameters<typeof postgres>[0]['contract'];
postgres({ contract, pg: new AppPool({ connectionString: 'postgresql://localhost/app' }) });
tsconfig.json: { "compilerOptions": { "module": "nodenext", "strict": true, "exactOptionalPropertyTypes": true, "noEmit": true, "skipLibCheck": true } }
$ tsc -p .
index.ts(9,22): error TS2375: Type 'AppPool' is not assignable to type 'Client | Pool' with 'exactOptionalPropertyTypes: true'.
Type '…/@[email protected]/…/index").Pool' is not assignable to type '…/@[email protected]/…/index").Pool'.
The types of 'options.onConnect' are incompatible between these types.
…
Property 'getTransactionStatus' is missing in type '…/@[email protected]/…").ClientBase' but required in type '…/@[email protected]/…").ClientBase'.
$ pnpm why @types/pg
@types/[email protected]
├─┬ @prisma/[email protected]
└─┬ @prisma/[email protected]
@types/[email protected]
└── (the app, devDependencies)
Found 2 versions of @types/pg
With @types/pg 8.20.4 it compiles.
Environment
macOS, Node 24.16, pnpm 12.11, TypeScript 7.0.2, PostgreSQL 17.
Additional context
Related, for Prisma 7: #29897 (@prisma/adapter-pg checks the pool against its own pg class).
Thanks for reporting this. We're looking into it now: whether we can reproduce it and what impact it has.
You can follow where this stands here: https://asks.prisma.cool/public/asks/01a1cac1-ade6-747d-9fea-8fd1646e25e3
Confirmed the cause from your repro: @prisma/orm-postgres pins pg 8.22.0 and @types/pg 8.20.4 exactly, so a pool typed against @types/pg 8.21.0 isn't assignable (TS2375) and pnpm why shows two copies. The immediate workaround that works today is pinning @types/pg to 8.20.4 and pg to 8.22.0 so only one copy exists. Longer term, declaring pg/@types/pg as peerDependencies with a range (e.g. ^8.20.0) seems right, since the runtime already checks the pool by shape (isPgPool), not class identity.