Next.js Discord

Discord Forum

Error Prisma

Unanswered
Black Mouth Cur posted this in #help-forum
Open in Discord
Black Mouth CurOP
Hi,
When I deploy on vercel I get a type error in my prisma file, but when I build locally it works.

7 Replies

Black Mouth CurOP
import { PrismaClient } from '@prisma/client'

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClient | undefined
}

const prismaInstance = globalForPrisma.prisma ?? new PrismaClient()

if (!globalForPrisma.prisma) {
  const dmmf = (prismaInstance as any)._dmmf || (prismaInstance as any)._engine?.dmmf
  
  let modelsWithDeletedAt: string[] = []
  
  if (dmmf?.datamodel?.models) {
    modelsWithDeletedAt = dmmf.datamodel.models
      .filter((model: any) => model.fields.some((field: any) => field.name === 'deleted_at'))
      .map((model: any) => model.name)
  }

  prismaInstance.$use(async (params, next) => {
    if (
      params.model &&
      modelsWithDeletedAt.includes(params.model) &&
      ['findFirst', 'findMany', 'findUnique', 'count', 'aggregate', 'groupBy'].includes(params.action)
    ) {
      params.args = params.args || {}
      params.args.where = params.args.where
        ? { ...params.args.where, deleted_at: null }
        : { deleted_at: null }
    }
    return next(params)
  })
}

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prismaInstance

export const prisma = prismaInstance
American black bear
can you paste code like this:

```tsx

CODE PASTE

```
American black bear
add "tsx" after first ``` as well
and can you share the exact error you are getting
@American black bear and can you share the exact error you are getting
Black Mouth CurOP
this is the error I receive
add prisma generate as a postinstall script in your package.json