skip to Main Content

I’m working with the basic Gatsby starter site and it compiles just fine, but the browser just shows the error mentioned in the title as well as a couple warnings.

It’s probably important to note that the error is gone when I completely remove the StaticQuery piece so the IndexPage component is just the opening and closing Layout tags. This gets rid of the error and the browser shows the header+footer of the Gatsby starter site.

I’ve made sure that my versions of react and react-dom are up to date in the package.json, I’ve reinstalled the packages via npm install, I’ve tried other versions of react, nothing is working.

The file that is failing (index.js):

import React from "react"
import { StaticQuery, GraphQL, Link } from "gatsby"

import Layout from "../components/layout"
import Image from "../components/image"
import SEO from "../components/seo"

const IndexPage = () => (
  <Layout>
    <StaticQuery query={GraphQL`{
        allWordpressPage {
          edges {
            node {
              id
              title
              content
            }
          }
        }
      }`} render={props => (
        <div> {props.allWordpressPage.edges.map(page => (
          <div key={page.node.id}>
            <h1>
              {page.node.title}
            </h1>
            <div dangerouslySetInnerHTML={{__html: page.node.content}} />
          </div>
        ))}
        </div>
      )}
    />
  </Layout>
)

export default IndexPage

The error and warnings that show in browser:

TypeError: Object(...) is not a function
IndexPage
src/pages/index.js:1
> 1 | import React from "react"
  2 | import { Link } from "gatsby"
  3 | 
  4 | import Layout from "../components/layout"
View compiled
▶ 17 stack frames were collapsed.
JSONStore._this.handleMittEvent
/Users/kennansmith/Desktop/Temp_Task_Folder/gatsby-wp/.cache/json-store.js:1
> 1 | import React from "react"
  2 | 
  3 | import PageRenderer from "./page-renderer"
  4 | import normalizePagePath from "./normalize-page-path"
View compiled
▶ 2 stack frames were collapsed.
r.<anonymous>
/Users/kennansmith/Desktop/Temp_Task_Folder/gatsby-wp/.cache/socketIo.js:20
  17 | // Try to initialize web socket if we didn't do it already
  18 | try {
  19 |   // eslint-disable-next-line no-undef
> 20 |   socket = io()
  21 | 
  22 |   const didDataChange = (msg, queryData) => {
  23 |     const id =
View compiled
▶ 24 stack frames were collapsed.

2

Answers


  1. Chosen as BEST ANSWER

    Ok, got it working again.

    The issue was that I was using GraphQL instead of graphql. The case-sensitivity was throwing the whole thing off. Replacing both instances of GraphQL with graphql fixed the issue and now I am seeing my data rendered on the page as intended.


  2. Maybe these imports are not the default ones?

    import Layout from "../components/layout"
    import Image from "../components/image"
    import SEO from "../components/seo"
    

    check if they ere exported as default, otherwise you shuld use {} import

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search