#Using the new `prisma-client` with NextJS

10 messages · Page 1 of 1 (latest)

pearl barn
#

It it normal that the new prisma client isn't compatible with the browser? When using prisma models in my client side next components, I get Cannot find module 'node:fs': Unsupported external type Url for commonjs reference

minor acornBOT
#

You selected the bot's instantaneous insights. Let me compile your answer right away!

minor acornBOT
# minor acorn You selected the bot's instantaneous insights. Let me compile your answer right ...

Short answer: yes—this is expected today.

  • Prisma Client itself does not run in the browser. You must use it only on the server (Route Handlers, Server Components, getServerSideProps, API routes). If Prisma code is bundled for the client, you’ll see errors like the ones you’re getting. [Comment summary; Next.js guidance]

  • With the new prisma-client generator, a dedicated browser entry point was added to let you import types and utilities in browser code without pulling Node APIs—but it intentionally does not include PrismaClient. You can safely import types like enums, Prisma.JsonValue, Decimal, etc., from the generated browser entry instead of importing from the server client. [feat: browser.ts; [Issue context]

What to do in Next.js:

  • Keep all PrismaClient usage in server-only files (e.g., server actions with "use server", route handlers, or getServerSideProps). [Next.js notes; [Guidance]
  • For client components that need types (model enums, Prisma.JsonValue), import them from the generated browser entry introduced by the new generator, not from @prisma/client. This avoids bundling Node modules like node:fs. [feat: browser.ts; [Issue]

If you still see node:fs errors, it likely means something is importing the server client/runtime into the client bundle—move those imports to server-only modules or switch to the browser types entry. [Issue]

minor acornBOT
pearl barn
#

@minor acorn How do I use the new prisma.config.ts fil?

dusk wren
pearl barn
dusk wren
#

Strange!

pearl barn