libsql-client-ts icon indicating copy to clipboard operation
libsql-client-ts copied to clipboard

Socket hangup when building site on vercel with nextjs

Open bdlowery opened this issue 1 year ago • 0 comments

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: CleanShot 2024-08-27 at 19 26 57

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.

bdlowery avatar Aug 28 '24 01:08 bdlowery