libsql-client-ts
libsql-client-ts copied to clipboard
Socket hangup when building site on vercel with nextjs
Sometimes when I build the site Prisma throws a socket hangup error. It also happens locally time to time, and if I hard refresh it goes away.
Error:
Packages:
"@libsql/client": "^0.4.3",
"@prisma/adapter-libsql": "^5.18.0",
"prisma": "^5.18.0",
"@prisma/client": "^5.18.0",
I'm creating the connection like this:
import { createClient } from '@libsql/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'
import { PrismaClient } from '@prisma/client'
declare global {
// eslint-disable-next-line no-var
var cachedPrisma: PrismaClient
}
let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
const libsql = createClient({
url: `${process.env.TURSO_DATABASE_URL}`,
authToken: `${process.env.TURSO_AUTH_TOKEN}`,
})
const adapter = new PrismaLibSQL(libsql)
prisma = new PrismaClient({ adapter })
} else {
if (!global.cachedPrisma) {
const libsql = createClient({
url: `${process.env.TURSO_DATABASE_URL}`,
authToken: `${process.env.TURSO_AUTH_TOKEN}`,
})
const adapter = new PrismaLibSQL(libsql)
global.cachedPrisma = new PrismaClient({ adapter })
}
prisma = global.cachedPrisma
}
export const db = prisma
and then using db like this in my code:
const tableName = await db.tableName.findMany({ })
Is there something I can do to prevent this? Maybe I'm not doing the connection correctly.