I deployed my project on Vercel and getting 500 error [id].tsx page but in localhost its fine

How can I fix that? https://guest-book.caglark.dev
Guest Book
Generated by create-t3-app
14 Replies
Neto
Neto2y ago
you should check vercel logs vercel -> [project] -> deployments -> select latest deployment -> functions -> reload the page should display the log on the server
Çağlar
Çağlar2y ago
yep, it says prisma is not defined
Çağlar
Çağlar2y ago
Neto
Neto2y ago
GitHub
prisma-examples/typescript/rest-nextjs-api-routes at latest · prism...
🚀 Ready-to-run Prisma example projects. Contribute to prisma/prisma-examples development by creating an account on GitHub.
Neto
Neto2y ago
you can check this example from prisma and gssp
Çağlar
Çağlar2y ago
I do the same thing,
//getServerSideProps
export const getServerSideProps = async (
context: GetServerSidePropsContext<{ id: string }>
) => {
const { id } = context.query;

const user = await prisma?.user.findUnique({
where: {
id: String(id),
},
include: {
_count: {
select: {
Post: true,
},
},
Post: {
where: {
published: false,
},
orderBy: {
createdAt: "desc",
},
},
},
});

if (user) {
const profile = JSON.parse(JSON.stringify(user));
return {
props: {
profile,
},
};
}
return {
redirect: {
destination: "/",
permanent: false,
},
};
};
//getServerSideProps
export const getServerSideProps = async (
context: GetServerSidePropsContext<{ id: string }>
) => {
const { id } = context.query;

const user = await prisma?.user.findUnique({
where: {
id: String(id),
},
include: {
_count: {
select: {
Post: true,
},
},
Post: {
where: {
published: false,
},
orderBy: {
createdAt: "desc",
},
},
},
});

if (user) {
const profile = JSON.parse(JSON.stringify(user));
return {
props: {
profile,
},
};
}
return {
redirect: {
destination: "/",
permanent: false,
},
};
};
Do you see something weird?
Neto
Neto2y ago
why prisma?.
Çağlar
Çağlar2y ago
I dont know it makes things simplier
Neto
Neto2y ago
my issue is the ?. it implies prisma may be nullable and probably is the cause of the issue
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Çağlar
Çağlar2y ago
thank you, I didnt realize that
Neto
Neto2y ago
on the example they just import elsewhere
import { PrismaClient } from "@prisma/client";

// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
//
// Learn more:
// https://pris.ly/d/help/next-js-best-practices

let prisma: PrismaClient

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.prisma) {
global.prisma = new PrismaClient()
}
prisma = global.prisma
}
export default prisma
import { PrismaClient } from "@prisma/client";

// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
//
// Learn more:
// https://pris.ly/d/help/next-js-best-practices

let prisma: PrismaClient

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.prisma) {
global.prisma = new PrismaClient()
}
prisma = global.prisma
}
export default prisma
Çağlar
Çağlar2y ago
yes sir you are totally right
Çağlar
Çağlar2y ago
@Neto @git commit -m "changes" +250k -3 that fixed my problem thank you again. https://guest-book.caglark.dev/profile/clatoh3bk0000vxvkqdd23xxg
| Guest Book
Generated by create-t3-app
Want results from more Discord servers?
Add your server