Stack: NextJS, Contentful + Now
Overview: Invoked contentful's getEntries() request within getInitialProps async function. In local environment, everything is working perfectly, I receive the posts then successfully pass them as props to the page where I can render them.
Issue: When I try to deploy with Now, I am getting this error:
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)
Code:
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;