Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in function useStaticQuery in ./.cache/gatsby-browser-entry.js:77 (After upgrade to v3) #29951

Closed
logemann opened this issue Mar 3, 2021 · 19 comments · Fixed by #30599
Closed
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@logemann
Copy link

logemann commented Mar 3, 2021

Description

After starting (yarn start) a migrated gatsby v3 project, i am getting a weird error in the frontend (see screenshot). When using browser console i see some stacktraces involving my SEO component (which has a very basic and fully functional staticQuery expression in there) and a stacktrace regarding reach router.

This error stays but when i make a modification to the source, lets say i change a letter in the JSX, the error disappears and i have my running site.

On the shell i see this after saving my pseudo change (after that everything works)

<i> [webpack-dev-middleware] wait until bundle finished: /__original-stack-frame?moduleId=.%2F.cache%2Fgatsby-browser-entry.js&lineNumber=117&columnNumber=11
<i> [webpack-dev-middleware] wait until bundle finished: /__original-stack-frame?moduleId=.%2F.cache%2Fgatsby-browser-entry.js&lineNumber=117&columnNumber=11

See below the stacktrace in the browser console when being in error mode:

Uncaught Error: The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
    at useStaticQuery (gatsby-browser-entry.js:77)
    at SEO (SEO.js:6)
    at renderWithHooks (react-dom.development.js:14985)
    at mountIndeterminateComponent (react-dom.development.js:17811)
    at beginWork (react-dom.development.js:19049)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
gatsby-browser-entry.js:77 Uncaught Error: The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
    at useStaticQuery (gatsby-browser-entry.js:77)
    at Footer (Footer.js:10)
    at renderWithHooks (react-dom.development.js:14985)
    at mountIndeterminateComponent (react-dom.development.js:17811)
    at beginWork (react-dom.development.js:19049)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
react-dom.development.js:20085 The above error occurred in the <SEO> component:

    at SEO (webpack-internal:///./src/components/App/SEO.js:23:26)
    at RecoilRoot (webpack-internal:///./node_modules/recoil/es/recoil.js:1723:3)
    at Layout (webpack-internal:///./src/components/App/Layout.js:20:23)
    at CloudEntwicklung
    at PageRenderer (webpack-internal:///./.cache/page-renderer.js:23:29)
    at PageQueryStore (webpack-internal:///./.cache/query-result-store.js:39:30)
    at RouteHandler
    at div
    at FocusHandlerImpl (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:359:5)
    at FocusHandler (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:330:19)
    at RouterImpl (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:235:5)
    at Location (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:64:23)
    at Router
    at ScrollHandler (webpack-internal:///./node_modules/gatsby-react-router-scroll/scroll-handler.js:34:35)
    at RouteUpdates (webpack-internal:///./.cache/navigation.js:304:32)
    at EnsureResources (webpack-internal:///./.cache/ensure-resources.js:22:30)
    at LocationHandler (webpack-internal:///./.cache/root.js:67:29)
    at LocationProvider (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:84:5)
    at Location (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:64:23)
    at Root
    at ee (webpack-internal:///./node_modules/gatsby-plugin-image/dist/index.browser-c5d45e0e.js:808:13)
    at StaticQueryStore (webpack-internal:///./.cache/query-result-store.js:127:32)
    at ErrorBoundary (webpack-internal:///./.cache/fast-refresh-overlay/components/error-boundary.js:24:35)
    at DevOverlay (webpack-internal:///./.cache/fast-refresh-overlay/index.js:97:23)
    at RootWrappedWithOverlayAndProvider

React will try to recreate this component tree from scratch using the error boundary you provided, LocationProvider.
index.js:80 Uncaught Error: The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
    at useStaticQuery (gatsby-browser-entry.js:77)
    at SEO (SEO.js:6)
    at renderWithHooks (react-dom.development.js:14985)
    at mountIndeterminateComponent (react-dom.development.js:17811)
    at beginWork (react-dom.development.js:19049)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
useStaticQuery @ gatsby-browser-entry.js:77
SEO @ SEO.js:6
react-dom.development.js:20085 The above error occurred in the <LocationProvider> component:

    at LocationProvider (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:84:5)
    at Location (webpack-internal:///./node_modules/@gatsbyjs/reach-router/es/index.js:64:23)
    at Root
    at ee (webpack-internal:///./node_modules/gatsby-plugin-image/dist/index.browser-c5d45e0e.js:808:13)
    at StaticQueryStore (webpack-internal:///./.cache/query-result-store.js:127:32)
    at ErrorBoundary (webpack-internal:///./.cache/fast-refresh-overlay/components/error-boundary.js:24:35)
    at DevOverlay (webpack-internal:///./.cache/fast-refresh-overlay/index.js:97:23)
    at RootWrappedWithOverlayAndProvider

React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.

(i shortened the stacktrace a little bit.)

Steps to reproduce

for me it was just starting the project.

Expected result

fully functional gatsby project ;-)

Actual result

this error screenshot.

Bildschirmfoto 2021-03-03 um 10 20 09

Environment

System:
OS: macOS 11.2.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.8.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.5.0 - /usr/local/bin/npm
Languages:
Python: 3.9.0 - /Users/ml/.pyenv/shims/python
Browsers:
Chrome: 88.0.4324.192
Safari: 14.0.3
npmPackages:
gatsby: ^3.0.0 => 3.0.0
gatsby-image: ^3.0.0 => 3.0.0
gatsby-plugin-google-analytics-reporter: ^1.1.1 => 1.1.1
gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
gatsby-plugin-google-tagmanager: ^3.0.0 => 3.0.0
gatsby-plugin-html-attributes: ^1.0.5 => 1.0.5
gatsby-plugin-image: ^1.0.0 => 1.0.0
gatsby-plugin-manifest: ^3.0.0 => 3.0.0
gatsby-plugin-netlify: ^3.0.0 => 3.0.0
gatsby-plugin-netlify-cms: ^5.0.0 => 5.0.0
gatsby-plugin-percy: ^0.1.4 => 0.1.4
gatsby-plugin-react-helmet: ^4.0.0 => 4.0.0
gatsby-plugin-react-helmet-canonical-urls: ^1.4.0 => 1.4.0
gatsby-plugin-react-svg: ^3.0.0 => 3.0.0
gatsby-plugin-robots-txt: ^1.5.5 => 1.5.5
gatsby-plugin-sass: ^4.0.0 => 4.0.0
gatsby-plugin-sharp: ^3.0.0 => 3.0.0
gatsby-plugin-sitemap: ^3.0.0 => 3.0.0
gatsby-plugin-styled-components: ^4.0.0 => 4.0.0
gatsby-remark-classes: ^1.0.0 => 1.0.0
gatsby-remark-copy-linked-files: ^3.0.0 => 3.0.0
gatsby-remark-custom-blocks: ^3.0.0 => 3.0.0
gatsby-remark-images: ^4.0.0 => 4.0.0
gatsby-remark-prismjs: ^4.0.0 => 4.0.0
gatsby-remark-relative-images: ^2.0.2 => 2.0.2
gatsby-source-filesystem: ^3.0.0 => 3.0.0
gatsby-transformer-json: ^3.0.0 => 3.0.0
gatsby-transformer-remark: ^3.0.0 => 3.0.0
gatsby-transformer-sharp: ^3.0.0 => 3.0.0
npmGlobalPackages:
gatsby-cli: 2.12.110

@logemann logemann added the type: bug An issue or pull request relating to a bug in Gatsby label Mar 3, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 3, 2021
@logemann logemann changed the title Error in function useStaticQuery in ./.cache/gatsby-browser-entry.js:77 Error in function useStaticQuery in ./.cache/gatsby-browser-entry.js:77 (After upgrade to v3) Mar 3, 2021
@wardpeet
Copy link
Contributor

wardpeet commented Mar 3, 2021

@logemann can you share your project or create any reproduction? Have you ran gatsby clean before the build?

@LekoArts LekoArts added topic: StaticQuery and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 3, 2021
@logemann
Copy link
Author

logemann commented Mar 3, 2021

yeah i ran gatsby clean. Thats what i always do when something weird happens. After more debugging, it seems it is always the StaticQuery in my SEO component which fails.

    const {site} = useStaticQuery(
        graphql`
      query {
        site {
          siteMetadata {
            title
            titleSuffix
            description
            image
            siteUrl
          }
        }
      }
    `);

But like i said. If the query would be broken, it wouldnt work after changing something and hit save. Unfortunately you only see a query number inside useStaticQuery gatsby code. So its hard to debug. Perhaps SiteMetadata is not up and running after development server has started but is ready after first save? Wouldnt make much sense to me since i can query SiteMetadata with Graphiql console. But i can confirm that removing the staticQuery from SEO component resolves the issue but of course is not a viable solution for me.

Currently i cant expose the whole project.

@logemann
Copy link
Author

logemann commented Mar 3, 2021

It seems it has something to do with gatsby-plugin-netlify-cms. When i remove this plugin, the error disappears.

@lomby92
Copy link

lomby92 commented Mar 9, 2021

The same happened to me, after the update to Gatsby 3 i had the error. In my case the error was in the index.js page.

Instead of using useStaticQuery inside the function that returns the JSX i have just added:

export const query = graphql`....

And changed the page in order to automatically receive data:

const IndexPage = ({data}) => {

Please note that i have netflify-cms but i didn't remove them as it should not be the real problem


UPDATE: all my previous info are wrong since the error is still here and as @logemann says it goes away at the first change (you can just save a file, triggering the site reload).
Note that in production everything works well and in development it happens only at the first start, subsequent reloads works.

@yurist38
Copy link
Contributor

yurist38 commented Mar 18, 2021

Totally the same for me! I'm trying to debug it for a couple of days already but no luck so far...

@logemann @lomby92 do you guys also use MDX? I am a bit suspicious that it has something to do with MDX...

@lomby92
Copy link

lomby92 commented Mar 18, 2021

Nope

  System:
    OS: Linux 5.4 KDE neon 5.21
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 12.20.0 - ~/.nvm/versions/node/v12.20.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.20.0/bin/npm
  Languages:
    Python: 2.7.18 - /usr/bin/python
  Browsers:
    Chrome: 89.0.4389.90
    Firefox: 86.0
  npmPackages:
    gatsby: ^3.0.4 => 3.0.4
    gatsby-plugin-image: ^1.0.0 => 1.0.0
    gatsby-plugin-manifest: ^3.0.0 => 3.0.0
    gatsby-plugin-netlify-cms: ^5.0.0 => 5.0.0
    gatsby-plugin-postcss: ^4.0.0 => 4.0.0
    gatsby-plugin-react-helmet: ^4.0.0 => 4.0.0
    gatsby-plugin-sharp: ^3.0.0 => 3.0.0
    gatsby-plugin-sitemap: ^3.0.0 => 3.0.0
    gatsby-remark-images: ^4.0.0 => 4.0.0
    gatsby-remark-relative-images: ^2.0.2 => 2.0.2
    gatsby-source-filesystem: ^3.0.0 => 3.0.0
    gatsby-transformer-remark: ^3.0.0 => 3.0.0
    gatsby-transformer-sharp: ^3.0.0 => 3.0.0
  npmGlobalPackages:
    gatsby-cli: 3.0.0

@LekoArts LekoArts added the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Mar 18, 2021
@LekoArts
Copy link
Contributor

Please upgrade to the latest version of all packages (we added some improvements to error handling in gatsby@3.1) and provide a minimal reproduction.

@yurist38
Copy link
Contributor

I've tried to upgrade everything yesterday, including the gatsby@3.1.0, didn't help. I'm builing a repro right now...

@yurist38
Copy link
Contributor

@LekoArts my minimal reproduction is ready https://github.com/yurist38/gatsby-3-static-query-issue
Please take a look at it... Thanks!

@logemann
Copy link
Author

@yurist38 i dont use MDX. So the error is not related to that.

@menttys
Copy link

menttys commented Mar 23, 2021

Having the same problem, neither 3 or 3.1 works for me.

@steviss
Copy link

steviss commented Mar 23, 2021

Having the same issue on Mac OS machine, while the project is running completely fine on a Windows machine. I've tried updating/upgrading all the packages to the latest version, but it still just displays the same error.

@LekoArts
Copy link
Contributor

LekoArts commented Mar 26, 2021

my minimal reproduction is ready yurist38/gatsby-3-static-query-issue
Please take a look at it... Thanks!

@yurist38 I followed the steps in the README and can't reproduce it. I also tried it with yarn, works, too.


For the rest: Please provide a reproduction if possible, only this way we can help :) Thanks!

@yurist38
Copy link
Contributor

@LekoArts it seems like something has changed since then. I've just tested it again with this reproduction repo and the issue is not appearing anymore... 🤔 Let me do more tests with my project next few days. I'll keep you updated.

@anhonestboy
Copy link

anhonestboy commented Mar 27, 2021

I got the same error on a clean project based on the blog starter with only 'netlify-cms-app' and 'netlify-cms-media-library-cloudinary' added.
There isn't any error about it during the deployment. The error message appears only in the browser.
The only fix that I've found at the moment is to save the index.js file after the deploy and for some reason, the error message goes away. At the moment I can't build the website.

Here you are the error message after the deploy:

Unhandled Runtime Error
One unhandled runtime error found in your files. See the list below to fix it:

Error in function useStaticQuery in ./.cache/gatsby-browser-entry.js:77

The result of this StaticQuery could not be fetched. This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues

 75 |     return context[query].data
  76 |   } else {
> 77 |     throw new Error(
     |          ^
  78 |       `The result of this StaticQuery could not be fetched.\n\n` +
  79 |         `This is likely a bug in Gatsby and if refreshing the page does not fix it, ` +
  80 |         `please open an issue in https://github.com/gatsby

And here you are the error I got during the build:

success run page queries - 0.328s - 7/7 21.31/s
success write out requires - 0.006s
success Building production JavaScript and CSS bundles - 44.344s
success Rewriting compilation hashes - 0.007s

 ERROR 

(node:38188) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning:
Compilation.hooks.normalModuleLoader was moved to
NormalModule.getCompilationHooks(compilation).loader
(Use `node --trace-deprecation ...` to show where the warning was created)


 ERROR 

(node:38188) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be
frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the
Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.

success Building HTML renderer - 2.729s
success Building static HTML for pages - 0.134s - 7/7 52.16/s
success Delete previous page data - 0.002s
success onPostBuild - 0.055s
info Done building in 57.195921656 sec

@phipag
Copy link

phipag commented Mar 30, 2021

Having the same issue on Mac OS machine, while the project is running completely fine on a Windows machine. I've tried updating/upgrading all the packages to the latest version, but it still just displays the same error.

Facing the same issue (working on Windows but not on Mac) with both StaticQuery component and useStaticQuery hook. It starts working when I make a pseudo change in the component using the static query.


  System:
    OS: macOS 11.2.3
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 7.7.5 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 89.0.4389.90
    Firefox: 86.0.1
    Safari: 14.0.3
  npmPackages:
    gatsby: ^3.1.1 => 3.1.2
    gatsby-plugin-fontawesome-css: ^1.1.0 => 1.1.0
    gatsby-plugin-i18n: ^1.0.1 => 1.0.1
    gatsby-plugin-image: ^1.1.1 => 1.1.2
    gatsby-plugin-netlify: ^3.1.0 => 3.1.0
    gatsby-plugin-netlify-cms: ^5.1.0 => 5.1.0
    gatsby-plugin-postcss: ^4.1.0 => 4.1.0
    gatsby-plugin-react-helmet: ^4.1.0 => 4.1.0
    gatsby-plugin-remove-serviceworker: ^1.0.0 => 1.0.0
    gatsby-plugin-sharp: ^3.1.1 => 3.1.2
    gatsby-remark-copy-linked-files: ^3.1.0 => 3.1.0
    gatsby-remark-images: ^4.1.0 => 4.1.1
    gatsby-remark-relative-images: ^2.0.2 => 2.0.2
    gatsby-source-filesystem: ^3.1.0 => 3.1.0
    gatsby-transformer-remark: ^3.1.0 => 3.1.0
    gatsby-transformer-sharp: ^3.1.0 => 3.1.0

Reproduction Repo: https://github.com/phipag/gatsby-i18n

The production build and deploy to Netlify is working and the error only happens in development mode.

@phipag
Copy link

phipag commented Mar 30, 2021

It seems it has something to do with gatsby-plugin-netlify-cms. When i remove this plugin, the error disappears.

I can now confirm that this issue does not appear when removing gatsby-plugin-netlify-cms. Maybe this is related to the changes to the webpack config the plugin makes: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js#L82

@ridem
Copy link
Contributor

ridem commented Mar 31, 2021

While this is fixed in gatsby, I can share the configuration that fixed the issue for me:

{
  resolve: "gatsby-plugin-netlify-cms",
  options: {
    ...yourOtherOptions,
    customizeWebpackConfig: (config) => {
      config.plugins = config.plugins.filter(
        (plugin) => plugin.constructor.name !== "StaticQueryMapper"
      );
    },
  },
}

If this is confirmed, it will just be a matter of adding that string to

![`MiniCssExtractPlugin`, `GatsbyWebpackStatsExtractor`].find(

@phipag
Copy link

phipag commented Mar 31, 2021

@ridem Thanks for sharing. It finally works now! Definitely worth adding this to the plugin directly so that others will not be affected by that anymore.

ridem added a commit to ridem/gatsby that referenced this issue Mar 31, 2021
The Netlify CMS plugin is spinning an extra webpack instance with almost
every plugin from gatsby. Reusing the `StaticQueryMapper` plugin caused
issues given how it's dealing with a Gatsby state.

Fixes gatsbyjs#29951

This commit also:
- removes `cssTests` which wasn't used anymore
- adds a clear TODO for how to get `excludeAssets` to be taken into account again
wardpeet pushed a commit that referenced this issue Apr 2, 2021
The Netlify CMS plugin is spinning an extra webpack instance with almost
every plugin from gatsby. Reusing the `StaticQueryMapper` plugin caused
issues given how it's dealing with a Gatsby state.

Fixes #29951

This commit also:
- removes `cssTests` which wasn't used anymore
- adds a clear TODO for how to get `excludeAssets` to be taken into account again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants