Prisma is in my client bundle and I don't know why

When I use Next.js' bundle analyzer, I can see that Prisma (@prisma/client) is in my client bundle (see screenshot). Some information: - Prisma v4.5.0 & Next.js v13.0.4 - I export a prisma variable like normal from a single file - I use that prisma variable in several pages for getStaticProps & getServerSideProps, as well as in the tRPC routes - I checked that I never import PrismaClient anywhere, besides where prisma is initialized - I do import the generated types from @prisma/client, but these shouldn't be responsible for that.... unless there is a new bug 😅 Does anyone have an idea what to look for to find out why it is in my bundle?
11 Replies
Neto
Neto•2y ago
I export a prisma variable like normal from a single file you answered yourself
bennettdev
bennettdevOP•2y ago
but that's how it's done in CT3A and also in the tRPC Prisma starter example?
Neto
Neto•2y ago
yes if you add a dependency and and use it it will be bundled
bennettdev
bennettdevOP•2y ago
but when you do the bundle analyzer for CT3A, Prisma is not part of the client bundle
needmorewood
needmorewood•2y ago
might be how gSSP works? try commenting those out and seeing how it turns out also if you are using trpc anyways why are you using prisma in gSSP and gSP?
bennettdev
bennettdevOP•2y ago
Instead of instantiating the Prisma client like so: export const prisma = new PrismaClient(...) I can literally export undefined like so: export const prisma = undefined ... and @prisma/client still remains in the client bundle. Maybe this comes from a new bug when importing the generated types?
Neto
Neto•2y ago
yes node dependency tree isnt fun to debug
bennettdev
bennettdevOP•2y ago
Maybe it has something to do with importing Prisma.validator or generated enums (which are not types, but consts...) oh no it probably is the validator To reproduce, create a fresh CT3A and put this into the _app.tsx
import { Prisma } from "@prisma/client";
const x = Prisma.validator()
import { Prisma } from "@prisma/client";
const x = Prisma.validator()
bennettdev
bennettdevOP•2y ago
Before and after....
bennettdev
bennettdevOP•2y ago
I guess it's missing tree shaking, don't know if this is rather a Prisma or Next.js issue...
bennettdev
bennettdevOP•2y ago
Update: It was not the validator, it was the enum. When having a Prisma enum model, you can import it in two ways from @prisma/client: either as const (enum-like) or as a string literal. Importing the const makes Prisma being part of the client bundle. More info: https://github.com/prisma/prisma/issues/13567#issuecomment-1332030096
GitHub
Separate enums and constants from the rest of the generated client ...
Problem You cannot easily import enum in client code. // src/app.ts import { MyEnum } from '@prisma/client' console.log(MyEnum) The problem is that all enums are in the same file wi...
Want results from more Discord servers?
Add your server