Unverified Commit cb565d69 authored by Samuel's avatar Samuel Committed by GitHub

Update: Add appropriate error message when for getServerSideProps invalid return value (#35887)

parent 07723be8
# Invalid getServerSideProps Return Value
#### Why This Error Occurred
In one of the page's `getServerSideProps` the return value had the incorrect shape.
#### Possible Ways to Fix It
Make sure to return the following shape from `getServerSideProps`:
```ts
export async function getServerSideProps(ctx: GetServerSidePropsContext) {
return {
props: { [key: string]: any }
}
}
```
### Useful Links
- [getServerSideProps](https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props)
......@@ -645,6 +645,10 @@
{
"title": "import-next",
"path": "/errors/import-next.md"
},
{
"title": "invalid-getserversideprops-return-value",
"path": "/errors/invalid-getserversideprops-return-value.md"
}
]
}
......
......@@ -255,12 +255,17 @@ export type RenderOptsPartial = {
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
const invalidKeysMsg = (methodName: string, invalidKeys: string[]) => {
const invalidKeysMsg = (
methodName: 'getServerSideProps' | 'getStaticProps',
invalidKeys: string[]
) => {
const docsPathname = `invalid-${methodName.toLocaleLowerCase()}-value`
return (
`Additional keys were returned from \`${methodName}\`. Properties intended for your component must be nested under the \`props\` key, e.g.:` +
`\n\n\treturn { props: { title: 'My Title', content: '...' } }` +
`\n\nKeys that need to be moved: ${invalidKeys.join(', ')}.` +
`\nRead more: https://nextjs.org/docs/messages/invalid-getstaticprops-value`
`\nRead more: https://nextjs.org/docs/messages/${docsPathname}`
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment