gatsby: StaticQuery fails if not inlined in built websites
Description
When you don’t inline the query for a StaticQuery and run gatsby build and open the corresponding website, the site breaks and just displays Loading (StaticQuery) forever.
Steps to reproduce
In my example. I saved the query to a variable and passed that variable to the query prop.
// in NavigationMenu
export const SocialBarQuery = graphql`
fragment SocialMediaFragment on Query {
site {
siteMetadata {
twitter
github
medium
steem
linkedIn
}
}
}
`
// in layout.js
const MainTemplateQuery = graphql`
query MainTemplateQuery {
...SocialMediaFragment
}
`
// in render
<StaticQuery query={MainTemplateQuery}
render={data => (
<section>
<NavigationMenu data={data} />
</section>
)}
/>
Make sure to run it with gatsby build, I did not have this issue while developing with gatsby develop.
As soon as you inline the query, it works:
<StaticQuery query={ graphql`
query MainTemplateQuery {
...SocialMediaFragment
}
`}
render={data => (
<section>
<NavigationMenu data={data} />
</section>
)}
/>
Expected result
The website should work.
Actual result
The website shows Loading (StaticQuery) forever.
Environment
System:
OS: Windows 10
Binaries:
npm: 5.3.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1.0
npmPackages:
gatsby: ^2.0.18 => 2.0.18
gatsby-link: ^2.0.4 => 2.0.4
gatsby-plugin-feed: ^2.0.6 => 2.0.6
gatsby-plugin-glamor: ^2.0.5 => 2.0.5
gatsby-plugin-google-analytics: ^2.0.6 => 2.0.6
gatsby-plugin-offline: ^2.0.5 => 2.0.5
gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0
gatsby-plugin-sharp: ^2.0.6 => 2.0.6
gatsby-remark-copy-linked-files: ^2.0.5 => 2.0.5
gatsby-remark-images: ^2.0.3 => 2.0.3
gatsby-remark-prismjs: ^3.0.1 => 3.0.1
gatsby-remark-responsive-iframe: ^2.0.5 => 2.0.5
gatsby-remark-smartypants: ^2.0.5 => 2.0.5
gatsby-source-filesystem: ^2.0.1 => 2.0.1
gatsby-transformer-remark: ^2.1.6 => 2.1.6
gatsby-transformer-sharp: ^2.1.3 => 2.1.3
error The system cannot find the path specified.
Error: The system cannot find the path specified.
- envinfo.js:1 Function.e.exports.sync
[npm]/[gatsby-cli]/[envinfo]/dist/envinfo.js:1:7778
...
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 16 (3 by maintainers)
@sigmasoldi3r I ran into the same issue. I found that @whmountains used Prismic in his setup (like me) and I started to debug against issue with this plugin. Turned out, that when I disabled
gatsby-source-prismic-graphql(and all graphql queries related to prismic) it started to work correctly.So, I found an issue related to
gatsby-source-prismic-graphql- it seems that this plugin somehow breaksuseStaticQueryhook. Didn’t have time to dig into that yet, but it doesn’t seem to be problem with Gatsby tough.https://github.com/birkir/gatsby-source-prismic-graphql/issues/101
I’ve had the same issue, being able to “solve” it by inlining the query. thanks everyone for sharing. This bug is sneaky, as everything seems fine while running in the development environment.
I have the same issue and in my case, inlining the queries does not seem to help. The problem only appears with
gatsby build.I was having similar issues with the StaticQueries not rendering properly. It might have to do with trying to
exportthe variable with the query. I still have theconstvariables, but they’re just no longer being exported.