birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

Getting "Uncaught TypeError: Cannot set property 'query' of undefined" on Netlify #136

Open julians300 opened 4 years ago

julians300 commented 4 years ago

My project works fine locally but when deploying to netlify I am getting js errors.

I followed this guide: https://prismic.io/docs/reactjs/getting-started/prismic-gatsby

Here is the repo: https://github.com/julians300/gatsby-test

Here is the project deployed to Netlify: https://naughty-golick-713de1.netlify.com/

Any help getting Prismic to work with Netlify would be appreciated!

sebastiansson commented 4 years ago

@julians300 Did you find a solution? Facing the same issue.

I have tried using the 3.4.0-beta.2 but that causes another error in my /templates files:

warn The GraphQL query in the non-page component ".../src/templates/page.js" will not be run.
Exported queries are only executed for Page components. It's possible you're
trying to create pages in your gatsby-node.js and that's failing for some
reason.

Template file page.js:

import React from 'react'
import { graphql } from 'gatsby'

const Page = ({ data }) => {
    console.log(data)
    return <div>Test</div>
}

export const query = graphql`
    query($uid: String!, $lang: String!) {
        prismic {
            content(uid: $uid, lang: $lang) {
                title
                body {
                    ... on PRISMIC_ContentBodyTest {
                        type
                        label
                        primary {
                            test_title
                        }
                    }
                }
            }
        }
    }
`

export default Page

gatsby-config.js

{
    resolve: 'gatsby-source-prismic-graphql',
    options: {
        repositoryName: 'test', // required
        defaultLang: 'sv-se', // optional, but recommended
        langs: ['sv-se', 'no'],
        previews: true,
        pages: [
            {
                type: 'Content',
                match: '/:lang?/:uid',
                path: '/', // placeholder page for unpublished documents
                component: require.resolve('./src/templates/page.js'),
                langs: ['se-sv', 'no'],
            },
        ],
    },
},

3.4.0 seems to be released on Github but is not available on Npm. Why is that @birkir?

EDIT: Got it working somehow, renamed page.js to content.js and it seemed to work. Probably something else...

birkir commented 4 years ago

It was tagged incorrectly, its available through @canary as usually.

So 3.4.1-alpha.0