Gridsome's createPages and createManagedPages doesn't create viewable pages

157 views Asked by At

I have the following code in my gridsome.server.js:

    api.createManagedPages(async ({ createPage }) => {
        const { data } = await axios.get('https://members-api.parliament.uk/api/Location/Constituency/Search?skip=0&take=20')
        data.items.forEach(item => {
            console.log(item.value.id);
            if (item.value.currentRepresentation !== null && typeof item.value.currentRepresentation === 'object') {
                createPage({
                    path: `/constituency/${item.value.id}`,
                    component: './src/templates/Constituency.vue',
                    context: {
                        id: item.value.id,
                        name: item.value.name,
                        startDate: item.value.startDate,
                        mpId: item.value.currentRepresentation.member.value.id,
                        mpName: item.value.currentRepresentation.member.value.nameDisplayAs,
                        mpParty: item.value.currentRepresentation.member.value.latestParty.name,
                        thumbnail: item.value.currentRepresentation.member.value.thumbnailUrl
                    }
                })
            }
        })
    })

Whether I change the code to createPages or createManagedPages I always get 404 not found errors when trying to visit /constituency/3292 for example.

That was previously. I've now revisted my code and when I run gridsome serve some update must have happened because I now get the following error:

TypeError: app.pages.data is not a function
    at createRoutes (/home/josh/Code/find-your-mp/node_modules/gridsome/lib/serve.js:57:34)
    at module.exports (/home/josh/Code/find-your-mp/node_modules/gridsome/lib/serve.js:29:18)

For some reason - even if I can console.log() the incoming data and it shows up it won't create the pages or the routes to the pages and gives the above error.

1

There are 1 answers

0
gxvr On

gridsome serve command is very unstable and only maintained occasionally. Did you try to run your app with gridsome develop if you are working locally? If that doesn't work I suggest using serve to run your app