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
Neto3y 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ğlarOP3y ago
yep, it says prisma is not defined
Çağlar
ÇağlarOP3y ago
Neto
Neto3y 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
Neto3y ago
you can check this example from prisma and gssp
Çağlar
ÇağlarOP3y 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
Neto3y ago
why prisma?.
Çağlar
ÇağlarOP3y ago
I dont know it makes things simplier
Neto
Neto3y ago
my issue is the ?. it implies prisma may be nullable and probably is the cause of the issue
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Çağlar
ÇağlarOP3y ago
thank you, I didnt realize that
Neto
Neto3y 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ğlarOP3y ago
yes sir you are totally right
Çağlar
ÇağlarOP3y 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