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
I export a prisma variable like normal from a single file
you answered yourselfbut that's how it's done in CT3A and also in the tRPC Prisma starter example?
yes
if you add a dependency and and use it
it will be bundled
but when you do the bundle analyzer for CT3A, Prisma is not part of the client bundle
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?
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?yes
node dependency tree isnt fun to debug
Maybe it has something to do with importing
Prisma.validator
or generated enums (which are not types, but const
s...)
oh no
it probably is the validator
To reproduce, create a fresh CT3A and put this into the _app.tsx
Before and after....
I guess it's missing tree shaking, don't know if this is rather a Prisma or Next.js issue...
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-1332030096GitHub
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...