Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket hangup when building site on vercel with nextjs #250

Open
bdlowery opened this issue Aug 28, 2024 · 0 comments
Open

Socket hangup when building site on vercel with nextjs #250

bdlowery opened this issue Aug 28, 2024 · 0 comments

Comments

@bdlowery
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant