next.js error: Error: Extra keys returned from getStaticPaths in / (props) Expected: {…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
next.js error: Error: Extra keys returned from getStaticPaths in / (props) Expected: { paths: [], fallback: boolean }
code: ```export async function getStaticPaths() { const client = new ApolloClient({ url: "https://api-us-east-1-shared-usea1-02.hygraph.com/v2/clf8mafq706pn01t9fb9y538j/master", cache: new InMemoryCache(), });
const data = await client.query({ query: gql
query Pages { page(where: { slug: "home" }) { heroText heroLink heroTitle slug heroBackground { url width height } } }, });console.log("data", data);
return { props: { data: "data.pages", }, }; }
code - Assistant
The error message suggests that there are extra keys being returned from the
getStaticPathsfunction that are not expected. The expected keys arepathsandfallback.Looking at your code, it seems that you are returning the
dataobject as a prop. However, you should be returning an object with the keyspathsandfallback, which are used to generate static pages with dynamic routes.Here is an example of how you could modify your code to return the expected object:
javascriptexport async function getStaticPaths() { const client = new ApolloClient({ url: "https://api-us-east-1-shared-usea1-02.hygraph.com/v2/clf8mafq706pn01t9fb9y538j/master", cache: new InMemoryCache(), }); const data = await client.query({ query: gql` query Pages { page(where: { slug: "home" }) { slug } } `, }); const paths = data.pages.map((page) => ({ params: { slug: page.slug }, })); return { paths, fallback: false, }; }