Suppressing server-only
Unanswered
aa55h posted this in #help-forum
aa55hOP
So i have a
import "server-only" statement in one of my files which does queries. i use this file inside of my prisma seeding functions, which causes it to throw and therefore crash. is there any way to suppress it?2 Replies
Ragdoll
The reason it's crashing is that prisma seed runs in a plain Node.js environment, which doesn't recognize the Next.js server-only package.
Quick fix: > You should separate your Prisma logic from the Next.js specific logic. Create a standalone db.ts or client.ts for Prisma that doesn't use server-only, and then import that into both your Next.js files and your seed script.
Alternatively, you can use a mock for the server-only package in your seed command, but the separation of concerns is the "cleaner" way.
Quick fix: > You should separate your Prisma logic from the Next.js specific logic. Create a standalone db.ts or client.ts for Prisma that doesn't use server-only, and then import that into both your Next.js files and your seed script.
Alternatively, you can use a mock for the server-only package in your seed command, but the separation of concerns is the "cleaner" way.
aa55hOP
i see