Skip to content

Commit f47ff45

Browse files
authored
#DC-3141: Fix pnpm monorepo export (#6943)
1 parent 7c6bec5 commit f47ff45

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,24 @@ Once the migration is successful, create a `client.ts` file to initialize Prisma
198198
```ts file=database/client.ts
199199
// add-start
200200
import { PrismaClient } from "./generated/client";
201-
import { withAccelerate } from '@prisma/extension-accelerate'
201+
import { withAccelerate } from "@prisma/extension-accelerate";
202202
203-
const prisma = new PrismaClient().$extends(withAccelerate())
203+
// Instantiate the extended Prisma client to infer its type
204+
const extendedPrisma = new PrismaClient().$extends(withAccelerate());
205+
type ExtendedPrismaClient = typeof extendedPrisma;
204206
205-
const globalForPrisma = global as unknown as { prisma: typeof prisma }
207+
// Use globalThis for broader environment compatibility
208+
const globalForPrisma = globalThis as typeof globalThis & {
209+
prisma?: ExtendedPrismaClient;
210+
};
206211
207-
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
212+
// Named export with global memoization
213+
export const prisma: ExtendedPrismaClient =
214+
globalForPrisma.prisma ?? extendedPrisma;
208215
209-
export { prisma };
216+
if (process.env.NODE_ENV !== "production") {
217+
globalForPrisma.prisma = prisma;
218+
}
210219
// add-end
211220
```
212221

0 commit comments

Comments
 (0)