I am encountering an issue in my nextjs
application, The project i am working on is an e-commerce application where backend framework used is laravel
and the frontend framework is nextjs.The application is currently hosted on Digital Ocean App Platform and has two separate environments, i.e production
and staging
.When i add a new product in admin panel, the new product is created and hence it is shown in homepage, but the problem is when i navigate to products detail page,and also when i hover on the product on homepage which uses nextjs Link
component and has prefetch
enabled it gives me 500 internal server error.
Nextjs and react version used:
{
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
}
Production:
Staging:
Local Machine
Below is the code for both homepage and product detail page :
Get static props for home page:
export async function getStaticProps() {
const queryClient = new QueryClient();
await queryClient.prefetchQuery({
queryKey: [KEYS.bannerList],
queryFn: getBannerList,
});
await queryClient.prefetchQuery({
queryKey: [KEYS.featuredCategory],
queryFn: fetchFeaturedCategory,
});
await queryClient.prefetchQuery({
queryKey: [KEYS.getAllHomeData],
queryFn: fetchAllHomeData,
});
return {
props: {
dehydratedState: dehydrate(queryClient),
},
revalidate: 10
};
}
Get static paths and getstatic props for product detail page:
export async function getStaticPaths() {
const data = await fetch(`${baseURL}/api/all-product`, {
cache: 'no-cache',
})
.then((response) => response.json())
.then((data) => data?.data);
const paths = await data?.map((product) => ({
params: { product_slug: product.slug },
}));
return {
paths: paths || [],
fallback: 'blocking',
};
}
export async function getStaticProps(context) {
const { product_slug } = context.params;
const queryClient = new QueryClient();
await queryClient.prefetchQuery({
queryKey: [KEYS.productsDetails, { product_slug }],
queryFn: () => getProductDetails(product_slug),
})
return {
props: {
dehydratedState: dehydrate(queryClient),
},
revalidate: 10
};
}
These are the general info’s that i get back from network tabs: GENERAL
RESPONSE HEADERS
What did you try and what were you expecting?
I tried to replicate the issue in local environment in which i had no luck , so my best option is to go to digital ocean’s dashboard and force rebuild and redeploy which only works until the new product is added.
I also tried by updating the version to nextjs
to latest stable version.
I tried using nextjs standalone output mode in local environment using docker, which is also working fine.
I am trying to figure out whether the error is from app platform side or nextjs framework side , since the problem is only arising on production environment.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Heya,
The best way to move forward is by checking logs. I’ll recommend you to check this page here:
Types of Logs
App Platform records several different types of information about your app to during each stage of its deployment. You can access and review the following logs:
What you need is either the Runtime log or the Crash log.