gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.2k stars 10.33k forks source link

Error loading a result for the page query in "/" in development after successful built #27644

Closed fredshevek closed 3 years ago

fredshevek commented 3 years ago

Description

This is a very weird issue which has started occurring recently. The development sequence runs successfully and I see the message:

You can now view website in the browser.
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use gatsby build
⠀
success Building development bundle - 10.845s

When I go to http://localhost:8000/ and hit enter, I receive the following:

Error loading a result for the page query in "/". Query was not run and no cached result was found.
Error loading a result for the page query in "/404.html". Query was not run and no cached result was found.
Error loading a result for the page query in "/dev-404-page". Query was not run and no cached result was found.

I've discovered by luck that if I wait around 5-10 mins, it starts to work. So I can visit / and other pages. But in the meantime, there are no messages or log into the terminal. As if there is a background process running. I've also noticed my Netlify deployments started to go up to 20 mins from the usual 4-5 minutes it takes. I guess Netlify is polling on index page and deploys when it gets a 200.

Steps to reproduce

Really don't know how to reproduce and what is causing this.

Expected result

To be able to navigate to / once build is successful.

Actual result

Error loading a result for the page query in "/". Query was not run and no cached result was found.

for around 10 mins, then it resumes normally.

Environment

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.13.1 - ~/.asdf/installs/nodejs/12.13.1/bin/node
    Yarn: 1.22.4 - ~/.asdf/shims/yarn
    npm: 6.12.1 - ~/.asdf/installs/nodejs/12.13.1/bin/npm
  Languages:
    Python: 3.7.2 - ~/.asdf/shims/python
  Browsers:
    Chrome: 86.0.4240.111
    Edge: 86.0.622.51
    Firefox: 79.0
    Safari: 14.0
  npmPackages:
    gatsby: ^2.24.85 => 2.24.85
    gatsby-image: ^2.4.21 => 2.4.21
    gatsby-plugin-fullstory: ^2.3.14 => 2.3.14
    gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
    gatsby-plugin-google-tagmanager: ^2.3.16 => 2.3.16
    gatsby-plugin-manifest: ^2.4.35 => 2.4.35
    gatsby-plugin-preload-fonts: ^1.2.28 => 1.2.28
    gatsby-plugin-react-helmet: ^3.3.14 => 3.3.14
    gatsby-plugin-sharp: ^2.6.43 => 2.6.43
    gatsby-plugin-sitemap: ^2.4.17 => 2.4.17
    gatsby-plugin-theme-ui: ^0.3.0 => 0.3.0
    gatsby-source-filesystem: ^2.3.35 => 2.3.35
    gatsby-source-prismic: ^3.1.4 => 3.2.1
    gatsby-transformer-sharp: ^2.5.19 => 2.5.19
  npmGlobalPackages:
    gatsby-cli: 2.12.111
OlBal commented 3 years ago

I am experiencing this same error since the latest Gatsby update. I tried Gatsby clean to clear the cache but that had no effect.

vladar commented 3 years ago

Hi @fredshevek and @OlBal !

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

fredshevek commented 3 years ago

Hi @vladar

Thanks for getting back. I'll see if I can create one.

@OlBal

Just wondered, how many pages you create programmatically? I used to create around 8000 pages in the exports.createPages hook with createPage action.

I've changed them to dynamic pages, so not compiling them at build time now. And the issue is no longer happening. So I suspect it has something to do with the createPage action

OlBal commented 3 years ago

@fredshevek

Honestly it was a 2 page site that was able to build and deploy up until a new update gave .cache errors which I fixed then it's struggled with finding page querys. I'll take a look later on today and see if that helps. Thanks for the update.

OlBal commented 3 years ago

I seem to have it working as a had a pathPrefix as part of my module exports in my gatsby.config file I forgot was there. So it was trying to query a path that doesn't exist anymore.

NikkiJonesR commented 3 years ago

I'm running into the same issue on all paths since updating Gatsby from 2.21.0 to version 2.25.1. ex. Error loading a result for the page query in "/dev-404-page". Query was not run and no cached result was found. Has there been any movement on this?

Amber-Williams commented 3 years ago

I have had the same issue as well for over a month now. As a temporary solution I found, when I comment out some plugins from the gatsby-config file and restart my gatsby develop that it will start up without the error.

While this would point to a plugin being the issue, I've commented out various ones each time and it looks unrelated to the actual plugins and more around caching of the config file.

vladar commented 3 years ago

Did anyone reproduce this reliably? We would like to investigate this further but it is hard without at least some reproduction.

fredshevek commented 3 years ago

For other reasons, I moved away from programmatic createPage to dynamic pages. So this is no longer happening in my case. But as that was the change that stopped this happening, maybe that could shed some light on

NikkiJonesR commented 3 years ago

I'm no longer experiencing this issue in the newest version of Gatsby - "^2.26.0", can anyone else confirm?

joe-lloyd commented 3 years ago

@NikkiJonesR I just tested "^2.26.0" on my project but no luck unfortunately. But good to know it fixed your issue, maybe it's a different package or config setting in my project.

ascorbic commented 3 years ago

Hi. I'm going to close this now, as we can't do much to help without a reproduction. If anybody is able to create a minimal reproduction for this using the latest gatsby then please do reopen the issue. Thanks!

alowdon commented 3 years ago

We were having issues with this as well; I didn't have chance to make a reproduction, but we haven't noticed it since upgrading to v2.27.2.

Isaac-Tait commented 3 years ago

This error popped up for me too.

Screen Shot 2020-12-19 at 5 20 58 PM

Here is my package.json info:

  "dependencies": {
    "@tailwindcss/postcss7-compat": "^2.0.2",
    "autoprefixer": "^9.8.6",
    "gatsby": "^2.29.1",
    "gatsby-awesome-pagination": "^0.3.6",
    "gatsby-image": "^2.8.0",
    "gatsby-plugin-feed": "^2.10.0",
    "gatsby-plugin-manifest": "^2.9.0",
    "gatsby-plugin-netlify": "^2.8.0",
    "gatsby-plugin-postcss": "^2.3.13",
    "gatsby-plugin-react-helmet": "^3.7.0",
    "gatsby-plugin-remove-serviceworker": "^1.0.0",
    "gatsby-plugin-sharp": "^2.11.1",
    "gatsby-plugin-typography": "^2.9.0",
    "gatsby-remark-copy-linked-files": "^2.7.0",
    "gatsby-remark-images": "^3.8.0",
    "gatsby-remark-prismjs": "^3.10.0",
    "gatsby-remark-responsive-iframe": "^2.8.0",
    "gatsby-remark-smartypants": "^2.7.0",
    "gatsby-source-filesystem": "^2.8.0",
    "gatsby-transformer-remark": "^2.13.0",
    "gatsby-transformer-sharp": "^2.9.0",
    "postcss": "^7.0.35",
    "prismjs": "^1.22.0",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
    "react-helmet": "^5.2.1",
    "react-pro-sidebar": "^0.4.4",
    "react-typography": "^0.16.19",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2",
    "typography": "^0.16.19",
    "typography-theme-wordpress-2016": "^0.16.19"
  },
  "devDependencies": {
    "eslint": "^7.16.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.21.5",
    "eslint-plugin-react-hooks": "^4.2.0",
    "prettier": "2.1.1"
  },

I took a stab at creating a minimal reproduction to recreate the errors. Of course, after setting it up the error went away on my initial project and I could not get it to occur in the minimal repo I spun up.

https://github.com/Isaac-Tait/bug-repro-gatsbyjs

Figured I would post here just in case anybody can use my minimal reproduction and to say that the error is still happening with gatsby 2.29.1

progital commented 3 years ago

@ascorbic @vladar how can I create a reproduction if it depends on my particular data set (I have ~3K posts) and/or my data source is password protected. I'm happy to invite you to my private repo but I can't make that data public / post it here. Please advise.

Camus1859 commented 3 years ago

The issue arose for me after I mistakenly deleted some files/folders. Maybe that can help someone EDIT

I solved my issue!

I started a new gatsby project and replaced my current cache and public folders with the cache and public folders of the new generated project.

This was my exact error:

" error loading a result for the page query in "index" / "/". query was not run and no cached result was found. error loading a result for the page query in "/". query was not run and no cached result was found."

HarshilShah commented 3 years ago

I’m seeing this same issue, and only after updating to Gatsby v3 (alongside the other peer dependencies).

For a clean build, the index and 404 pages are being copied over and working just fine, as are my markdown posts set up via createPages, but for all other pages in src/pages the 404 page is rendering instead.

If I do a clean develop run it generates the pages on load and there’s no error.

However if I run develop after a build, it does not generate the pages anymore, and here’s the error I see, alongside the development 404 page:

Error loading a result for the page query in “about" / “about". Query was not run and no cached result was found. Error loading a result for the page query in "/about". Query was not run and no cached result was found.

  Error: Error loading a result for the page query in "/about". Query was not run and no cached result was found.

  - get-page-data.ts:118 readPageData
    [blog]/[gatsby]/src/utils/get-page-data.ts:118:11

  - start-server.ts:305 
    [blog]/[gatsby]/src/utils/start-server.ts:305:24

To be clear, the /about page here is a plain JS file, no GraphQL involved. I thought this was related to query on demand and so set the flag to disable it but no dice even so.

Getting a minimal repro might take some time but if any team members want access to my repo to poke around I’d be happy to give access.

HarshilShah commented 3 years ago

Just filed a new issue for this: #29946

demeralde commented 3 years ago

I suddenly started experiencing this issue during development after clearing my cache, deleting node_modules, and reinstalling dependencies. The exact same code was working perfectly fine before:

Error: Error loading a result for the page query in "/404.html". Query was not run and no cached result was found.

  - get-page-data.ts:118 readPageData
    [beach-bliss-aldinga]/[gatsby]/src/utils/get-page-data.ts:118:11

The only difference to this issue being it's trying to redirect from the index page to the 404 page (the index page won't load at all).

Any ideas? I'll report back if I find a solution.

demeralde commented 3 years ago

Looks like npm rebuild --update-binary did the trick. This also works with Yarn without creating a package-lock.json file (Yarn doesn't have its own command for this, AFAIK).

FelDev commented 3 years ago

I also randomly got that error using Gatsby 3.4.0 npm rebuild --update-binary didn't do the trick Then I tried gatsby clean and everything worked again.

Besides having the FAST_DEV flag set to true, not much is special about my setup. I do not use the gatsby-plugin-remove-trailing-slashes mentionned in #29946

My list of plugins:

ZaidKhan144 commented 3 years ago

@FelDev You are Legend!

FraserThompson commented 3 years ago

I'm still seeing this bug. None of the solutions work and I'm not using gatsby-plugin-remove-trailing-slashes.

Clearing the cache works for the first build, but not the second.

I'm using createPages in gatsby-node.js, but the error only occurs on some of those pages. The code which generates the pages which cause the error:

  result.data.blogsByTag.group.forEach(({ fieldValue }) => {
    createPage({
      path: `/blog/tags/${fieldValue}`,
      component: layouts.tags,
      context: {
        tag: fieldValue,
      },
    })
  })
Strangehill commented 3 years ago

having same issue after I added about a dozen new pages (all very similar so I added them all in one go using command line). Perhaps the development server had trouble keeping up with file changes and only partially updated cache because gatsby clean fixed it.

phun-ky commented 2 years ago

I get this from time to time (with the latest version of gatbsy(4)). only thing that helps (not always) is to gatsby clean and restart dev server..

KenSkudderPWW commented 2 years ago

In case this is helpful: I have seen this type of error sometimes when I check out a branch in git that causes a page to exist that didn't exist when I started the development server, and then try to visit that page in my browser. Restarting the development server alone has not helped for me, but running gatsby clean in combination with restarting the development server has helped. I am not using createPages, all my pages are statically defined. Gatsby version 3.14.2, Gatsby CLI version 3.14.1.

Nowaker commented 2 years ago

I was getting this error on gatsby develop. Could not find an issue. It turned out the index page was buggy but Gatsby never showed any error message.

    indexHTMLActivity.start();
    await createIndexHtml(indexHTMLActivity);
    indexHTMLActivity.end();

There is a problem in Gatsby core. If index page is broken, and its build triggers a warning, you'll never see that warning. Instead, just a timeout, which is very ambiguous.

I was able to at least see what the error is by executing GATSBY_EXPERIMENTAL_DEV_SSR=true gatsby develop. Even though I have no intention of using DEV_SSR mode, the logic of develop server in this mode does not require that index page successfully builds. Thanks to that, the dev server starts, and warnings are now allowed to be printed:

/home/XXX/src/pages/index.js
  8:7  warning  Imported JSX component SEO must be in PascalCase  react/jsx-pascal-case

Having fixed the underlying issue with the index page, the develop server now starts without an issue.

While a coding issue with the index page is ultimately the root cause, it's undeniable that it's Gatsby suppresses the warning, leaving anyone who hits this issue in the dark.

Nowaker commented 2 years ago

I think it can be reopened now, @ascorbic. Please reevaluate.

matthewhoth commented 2 years ago

@Nowaker Your solution also allowed my local dev server to run. Strange combination of successful builds / unsuccessful builds though.

Normal gatsby develop = Error: Couldn't get query results for "/" in 15.000s.

GATSBY_EXPERIMENTAL_DEV_SSR=true gatsby develop = Succesful build with Pascal Case warning.

Normal yarn build = Successful build with a warning.

Netlify yarn build = Unsuccess with misleading error message.

Even after solving the Pascal Case warning the problem persists, but there is no longer any kind of reasonable warning.

Just the Error: Couldn't get query results for "/" in 15.000s. failure which is useless.

In what is probably a very specific issue, install 'gatsby-plugin-preload-link-crossorigin' breaks my ability to dev everytime.

Remove it, and there are no problems.

openscript commented 1 year ago

I think I described a related problem here: #36675

haneenmahd commented 1 year ago

I am experiencing this same error since the latest Gatsby update. I tried Gatsby clean to clear the cache but that had no effect.

I could fix it by stopping the dev server and running gatsby clean and restarting the server again.

That worked for me ✅

joaosilva-lp commented 7 months ago

I am experiencing this same error since the latest Gatsby update. I tried Gatsby clean to clear the cache but that had no effect.

I could fix it by stopping the dev server and running gatsby clean and restarting the server again.

That worked for me ✅

Thank you man! It really helped

timtop commented 5 months ago

I had this same issue a simple yarn clean or gatsby clean solved