Cannot read property 'page' of undefined and the page reset always when I start any gatsby project now.
for example, use gatsby new gatsby-site even not.
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
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')
})
})
})
}
Most helpful comment
@FengShangWuQi could you provide any more details about what exactly the problem was and how you fixed it?