Prisma Logger Error After Extending Prisma Client

Hi,
I tried to extend the prisma client using this eoin-obrien/prisma-extension-kysely: Drop down to raw SQL in Prisma without sacrificing type safety! (github.com). But got an error because of the logger.

api | TypeError: config.db.$on is not a function
api |     at /Users/downey/Documents/Dev.nosync/budget/node_modules/@redwoodjs/api/dist/logger/index.js:268:17
api |     at Array.forEach (<anonymous>)
api |     at handlePrismaLogging (/Users/downey/Documents/Dev.nosync/budget/node_modules/@redwoodjs/api/dist/logger/index.js:253:21)
api |     at Object.<anonymous> (/Users/downey/Documents/Dev.nosync/budget/api/src/lib/db.ts:38:1)
api |     at Module._compile (node:internal/modules/cjs/loader:1241:14)
api |     at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
api |     at Module.load (node:internal/modules/cjs/loader:1091:32)
api |     at Module._load (node:internal/modules/cjs/loader:938:12)
api |     at Module.require (node:internal/modules/cjs/loader:1115:19)
api |     at require (node:internal/modules/helpers:130:18)

After searching around I found this github issue $on argument type error when extending prisma client · Issue #11986 · prisma/prisma (github.com)

Currently I just remove the logging in the api/src/lib/db.ts to avoid the problem.

handlePrismaLogging({
  db,
  logger,
  logLevels: ['info', 'warn', 'error'],
})

I believe I ran into this extending Prisma client for Accelerate.
This is how my db.js is setup in api/src/lib/db.js

import { PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'

import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'

const prisma = new PrismaClient({
  log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
  db: prisma,
  logger,
  logLevels: ['info', 'warn', 'error'],
})

export const db = prisma.$extends(withAccelerate())

That fixes the problem. Thanks a lot!

2 Likes

Thanks for the help!