Fix server error on profile page in production (Vercel)
Prisma bundles a native database engine binary matched to whatever machine runs "prisma generate." Without an explicit binaryTargets list, it only bundles the engine for the local build machine - which doesn't match Vercel's serverless runtime. Every database call then crashed at runtime with no useful error, which is what showed up as "server error" right after logging in (the profile page is the first one that reads from the database). Added "rhel-openssl-3.0.x" (Vercel's actual runtime) alongside "native" so both platforms get a working engine. Also wrapped the profile page's database calls in a try/catch so any future failure shows a plain "something went wrong, try again" message instead of Next.js's raw crash screen. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VL5YUEf2B9LG4xdVUQwcSg
This commit is contained in:
2 files changed
+23
-7
No files matched your search
@@ -1,5 +1,9 @@
|
|||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
|
// "native" builds for local dev; "rhel-openssl-3.0.x" is the engine
|
||||||
|
// Vercel's serverless functions actually run on. Without both, database
|
||||||
|
// calls crash in production with no useful error message.
|
||||||
|
binaryTargets = ["native", "rhel-openssl-3.0.x"]
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
|
|||||||
@@ -11,12 +11,24 @@ export default async function ProfilePage() {
|
|||||||
redirect("/login");
|
redirect("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
await ensureDb();
|
let user;
|
||||||
|
try {
|
||||||
const user = await prisma.user.findUnique({
|
await ensureDb();
|
||||||
where: { id: session.user.id },
|
user = await prisma.user.findUnique({
|
||||||
select: { id: true, name: true, email: true, age: true, bio: true },
|
where: { id: session.user.id },
|
||||||
});
|
select: { id: true, name: true, email: true, age: true, bio: true },
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("failed to load profile:", err);
|
||||||
|
return (
|
||||||
|
<main className="mx-auto flex min-h-screen max-w-sm flex-col items-center justify-center gap-4 px-6 py-12 text-center">
|
||||||
|
<h1 className="text-2xl font-bold text-brand">Something went wrong</h1>
|
||||||
|
<p className="text-gray-600">
|
||||||
|
We couldn't load your profile right now. Please try again in a moment.
|
||||||
|
</p>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
redirect("/login");
|
redirect("/login");
|
||||||
|
|||||||
Reference in new issue
Block a user