gpt4 book ai didi

reactjs - NextJS + Contentful => getInitialProps 中的 getEntries 请求中断了生产构建

转载 作者:行者123 更新时间:2023-12-04 10:45:29 32 4
gpt4 key购买 nike

堆栈 : NextJS, Contentful + Now

概览 :在 getInitialProps 异步函数中调用 contentful 的 getEntries() 请求。在本地环境中,一切正常,我收到帖子然后成功地将它们作为 Prop 传递到我可以呈现它们的页面。

问题 :当我尝试使用 Now 进行部署时,出现此错误:

Error: The resource could not be found. at notFoundError (/zeit/31b54c53/node_modules/contentful/dist/contentful.node.js:7731:19) at /zeit/31b54c53/node_modules/contentful/dist/contentful.node.js:7854:13 at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Function.module.exports.HB77.Post.getInitialProps (/zeit/31b54c53/.next/serverless/pages/p/[id].js:1198:15) at async loadGetInitialProps (/zeit/31b54c53/.next/serverless/pages/p/[id].js:3451:17) { sys: { type: 'Error', id: 'NotFound' }, details: { type: 'Entry', id: 'undefined', environment: 'master', space: undefined } } Error occurred prerendering page "/p/[id]" https://err.sh/zeit/next.js/prerender-error: Error: Failed to render serverless page at Object._default [as default] (/zeit/31b54c53/node_modules/next/dist/export/worker.js:12:212) at processTicksAndRejections (internal/process/task_queues.js:93:5)



代码 :
const Post = props => {
...
}

Post.getInitialProps = async function({ query }) {

const contentfulClient = contentful.createClient({
accessToken: `${process.env.ACCESS_TOKEN}`,
space: `${process.env.SPACE}`
});

const res = await contentfulClient.getEntry(`${query.id}`);

return {
post: res
};
};

export default Post;

最佳答案

看起来您的 ENV 可能缺少:

details: { type: 'Entry', id: 'undefined', environment: 'master', space: undefined } 
process.env.spaceundefined

关于reactjs - NextJS + Contentful => getInitialProps 中的 getEntries 请求中断了生产构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59725254/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com