I am using the vercel CLI command 'vercel' to deploy my Next Js app to vercel. Currently the deployment fails when I try to return paths from generateStaticParams in a dynamic page with the url /listings/[category]/[...listing]/page.js
. It however works when I set the return value to an empty array. Find content of the [...listing]/page.js below:
export const dynamicParams = true; // true | false,
// or Dynamic metadata
export async function generateMetadata({params: { listing: [slug, listingId] },searchParams}, parent) {
const listing = await getListing(listingId)
return {
title: listing.attributes.title,
openGraph: {
// images: ['/some-specific-page-image.jpg', ...previousImages],
},
};
}
export async function generateStaticParams() {
const listingsResp = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/listings?populate=images,amenities.*,amenities.icon,videos.*,property_status.*,currency.*,payment_duration.*,page_views.*,property_owner.*`)
const listings = await listingsResp.json()
const paths = listings.data.map(listing=>({
category: listing.attributes.property_status.data.attributes.slug,
listing: [listing.attributes.slug, listing.id.toString()]
}))
return paths
}
export default async function Listing({params: { listing: [slug, listingId] }}){
const listingData = getListing(listingId)
const relatedListingData = getRelatedListings(listingId,5)
const [listing, relatedListings] = await Promise.all([listingData,relatedListingData])
return (
<div className='container-fluid pb-5'>
Listing detail
</div>
)
}
Error message:
- warn Entire page /listingsv2/[category]/[listing] deopted into client-side rendering. https://nextjs.org/docs/messages/deopted-into-client-rendering /listingsv2/[category]/[listing]
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)
at successSteps (node:internal/deps/undici/undici:6472:27)
at node:internal/deps/undici/undici:1145:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)
at successSteps (node:internal/deps/undici/undici:6472:27)
at node:internal/deps/undici/undici:1145:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)
at successSteps (node:internal/deps/undici/undici:6472:27)
at node:internal/deps/undici/undici:1145:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)
at successSteps (node:internal/deps/undici/undici:6472:27)
at node:internal/deps/undici/undici:1145:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I cant seem to wrap my head around why that is happening. Anyone experiencing or ever experienced this before? How did you solve this. Thanks