伙计们,当我尝试运行"npm run build"在我的nextjs中,
我的文件在
pages/agenda/[...uri].tsx
运行问题的那部分代码
export async function getStaticProps({ params }: { params: any }) {
const tournamentData = await getTournamentData(params.uri[0])
return {
props: {
tournamentData
}
}
}
export async function getStaticPaths() {
const paths = await getAllTournamentIds()
return {
paths,
fallback: false
}
}
错误:
info - Collecting page data
[ ] info - Generating static pages (0/14)
Error occurred prerendering page "/noticia/[object Object]/1". Read more: https://nextjs.org/docs/messages/prerender-error
FetchError: invalid json response body at https://api.torneio.app/v1/news?id=[object%20Object] reason: Unexpected token < in JSON at position 0
at /Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/node_modules/next/dist/compiled/node-fetch/index.js:1:49606
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async getPostData (/Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/.next/server/chunks/776.js:82:19)
at async getStaticProps (/Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/.next/server/pages/noticia/[...uri].js:254:22)
at async renderToHTML (/Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/node_modules/next/dist/server/render.js:488:20)
at async /Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/node_modules/next/dist/export/worker.js:253:36
at async Span.traceAsyncFn (/Users/begomarcus/Workspace/projects/platform-beach-tennis/nextjs/node_modules/next/dist/trace/trace.js:79:20)
我真的不明白这里发生了什么,任何线索都会帮助很多!
感谢@juliomalves我审查了我的文件,我从API请求数据,并发现了一个错误与我的地图
之前是:
const postsData = data.map(({ id: string, slug: string }) => {
return {
params: {
uri: [`${id}`, `${slug}`]
}
}
})
所以我改成:
const postsData = data.map(({ id, slug }: { id: string, slug: string }) => {
return {
params: {
uri: [`${id}`, `${slug}`]
}
}
})
打字错误和正确的参数。