Gatsby: Cannot read property 'page' of undefined and the page reset always

Created on 17 Sep 2019  路  5Comments  路  Source: gatsbyjs/gatsby

Description

Cannot read property 'page' of undefined and the page reset always when I start any gatsby project now.

Steps to reproduce

for example, use gatsby new gatsby-site even not.

Environment

System:
OS: macOS 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.3 - /usr/local/bin/node
npm: 6.11.3 - /usr/local/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 76.0.3809.132
Safari: 12.1.2
npmPackages:
gatsby: ^2.15.16 => 2.15.16
gatsby-image: ^2.2.19 => 2.2.19
gatsby-plugin-manifest: ^2.2.16 => 2.2.16
gatsby-plugin-offline: ^3.0.7 => 3.0.7
gatsby-plugin-react-helmet: ^3.1.7 => 3.1.7
gatsby-plugin-sharp: ^2.2.22 => 2.2.22
gatsby-source-filesystem: ^2.1.22 => 2.1.22
gatsby-transformer-sharp: ^2.2.14 => 2.2.14
npmGlobalPackages:
gatsby-cli: 2.7.47

Most helpful comment

@FengShangWuQi could you provide any more details about what exactly the problem was and how you fixed it?

All 5 comments

I found the script has an unsupported MIME type ('text/html') error, and resolved.

@FengShangWuQi could you provide any more details about what exactly the problem was and how you fixed it?

For my future friends, I (think I) was getting this issue because I was calling createPage inside of onCreateNode. To fix it, I refactored to call createPage inside of createPages instead.

@tylermcginnis can you provide a code sample?

@mlocalhost

before

exports.onCreateNode = ({ node, actions ) = {
  if (node.type === 'MyType') {
    return actions.createPage({
      path: '/path',
      component: resolve('./path/to/template.js')
    })
  }
}

after

exports.createPages = ({ graphql, actions ) => {
  return graphql(myQuery).then(({ data ) => {
    return data.allData.edges.map(({ node }) => {
      actions.createPage({
        path: '/path',
        component: resolve('./path/to/template.js')
      })
    })
  })
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

timbrandin picture timbrandin  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

rossPatton picture rossPatton  路  3Comments