gatsbyjs / gatsby

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

Pages not generated in Gatsby v3 build #29946

Closed HarshilShah closed 3 years ago

HarshilShah commented 3 years ago

Description

I just updated my site to Gatsby v3 and have run into a bug. Pages in src/pages other than index.js and 404.js don’t get generated anymore when running gatsby build

If I do a clean develop run it generates the pages on first load and there’s no error. 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.

However if I run develop after 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.

Steps to reproduce

All I’ve done here is update a previously functioning site Gatsby to v3, and then all the various official plugins to the latest versions as well. The site only has a few pages and a blog section where Markdown files are imported via createPages.

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, or post any other specific info required.

In the meantime, here’s my package.json. and gatsby-config

package.json ``` { "name": "HarshilShah", "description": "Harshil Shah's website", "version": "1.0.0", "author": "Harshil Shah ", "dependencies": { "gatsby": "^3.0.0", "gatsby-plugin-feed": "^3.0.0", "gatsby-plugin-react-helmet": "^4.0.0", "gatsby-plugin-react-svg": "^3.0.0", "gatsby-plugin-sass": "^4.0.0", "gatsby-plugin-sharp": "^3.0.0", "gatsby-remark-copy-linked-files": "^3.0.0", "gatsby-remark-images": "^4.0.0", "gatsby-remark-numbered-footnotes": "^1.0.1", "gatsby-remark-vscode": "^3.0.1", "gatsby-source-filesystem": "^3.0.0", "gatsby-transformer-remark": "^3.0.0", "gatsby-transformer-sharp": "^3.0.0", "github-plus-theme": "github:thenikso/github-plus-theme", "littlefoot": "^2.0.3", "night-owl": "github:sdras/night-owl-vscode-theme", "react": "^17.0.1", "react-dom": "^17.0.1", "react-helmet": "^6.1.0", "sass": "^1.32.7" }, "keywords": [ "gatsby" ], "scripts": { "build": "gatsby build", "develop": "gatsby develop", "format": "prettier --write 'src/**/*.js'", "test": "echo \"Error: no test specified\" && exit 1" }, "devDependencies": { "gatsby-plugin-remove-trailing-slashes": "^3.0.0" } } ```
gatsby-config.js ``` const config = require(`./config/site-config`) module.exports = { siteMetadata: { configuration: config, title: config.siteTitle, description: config.siteDescription, siteUrl: config.siteUrl, }, plugins: [ 'gatsby-plugin-react-helmet', { resolve: `gatsby-source-filesystem`, options: { name: `blog`, path: `${__dirname}/${config.blogDirectory}` } }, `gatsby-plugin-sass`, `gatsby-plugin-sharp`, `gatsby-transformer-sharp`, { resolve: `gatsby-transformer-remark`, options: { plugins: [ { resolve: `gatsby-remark-copy-linked-files`, options: { ignoreFileExtensions: [`jpg`, `jpeg`], }, }, { resolve: `gatsby-remark-vscode`, options: { theme: { default: 'GitHub Plus', dark: 'Night Owl (No Italics)' }, extensions: ['github-plus-theme', 'night-owl'], injectStyles: false } }, { resolve: `gatsby-remark-images`, options: { linkImagesToOriginal: false, wrapperStyle: `max-width: none !important;` } }, { resolve: `gatsby-remark-numbered-footnotes`, }, ] } }, { resolve: 'gatsby-plugin-react-svg', options: { include: /src\/assets/ } }, `gatsby-plugin-remove-trailing-slashes`, { resolve: `gatsby-plugin-feed`, options: { query: ` { site { siteMetadata { title description siteUrl site_url: siteUrl } } } `, feeds: [ { serialize: ({ query: { site, allMarkdownRemark } }) => { return allMarkdownRemark.edges.map(edge => { return Object.assign({}, edge.node.frontmatter, { description: edge.node.frontmatter.description, url: site.siteMetadata.siteUrl + config.blogPrefix + edge.node.frontmatter.slug, guid: site.siteMetadata.siteUrl + config.blogPrefix + edge.node.frontmatter.slug, custom_elements: [{ "content:encoded": edge.node.html }], }) }) }, query: ` { allMarkdownRemark( limit: 1000, sort: { order: DESC, fields: [frontmatter___date] } ) { edges { node { excerpt html frontmatter { title description date slug } } } } } `, output: config.rss, title: "Harshil Shah", }, ], }, }, ] } ```

Expected result

All pages in src/pages should be generated any copied over at build time.

Actual result

Only the index and 404 pages are generated, for the rest Gatsby shows 404 pages.

Environment

Environment ``` System: OS: macOS 11.2.2 CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/opt/node@14/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.11 - /usr/local/opt/node@14/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 88.0.4324.192 Edge: 88.0.705.74 Firefox: 85.0.2 Safari: 14.0.3 npmPackages: gatsby: ^3.0.0 => 3.0.0 gatsby-plugin-feed: ^3.0.0 => 3.0.0 gatsby-plugin-react-helmet: ^4.0.0 => 4.0.0 gatsby-plugin-react-svg: ^3.0.0 => 3.0.0 gatsby-plugin-remove-trailing-slashes: ^3.0.0 => 3.0.0 gatsby-plugin-sass: ^4.0.0 => 4.0.0 gatsby-plugin-sharp: ^3.0.0 => 3.0.0 gatsby-remark-copy-linked-files: ^3.0.0 => 3.0.0 gatsby-remark-images: ^4.0.0 => 4.0.0 gatsby-remark-numbered-footnotes: ^1.0.1 => 1.0.1 gatsby-remark-vscode: ^3.0.1 => 3.2.0 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 ```
pieh commented 3 years ago

Managed to reproduce it. It seems to be caused be caused by gatsby-plugin-remove-trailing-slashes (without that plugin things do work). Will dig more into the issue

pieh commented 3 years ago

All right - due to gatsby-plugin-remove-trailing-slashes changing paths of pages our tracker ( https://github.com/gatsbyjs/gatsby/blob/3f938652fd2a4406fed03743dc7f657db5c6a60d/packages/gatsby/src/redux/reducers/html.ts ) things the page was deleted and schedule pages that originally had trailing slashes to be deleted. However new pages result in same artificats pretty much and those get builds ... only to be deleted later:


{
  toRegenerate: [
    '/hello-world',
    '/my-second-post',
    '/new-beginnings',
    '/',
    '/404.html',
    '/404',
    '/no-query',
    '/using-typescript'
  ],
  toDelete: [
    '/hello-world/',
    '/my-second-post/',
    '/new-beginnings/',
    '/404/',
    '/no-query/',
    '/using-typescript/'
  ]
}

https://github.com/gatsbyjs/gatsby/blob/3f938652fd2a4406fed03743dc7f657db5c6a60d/packages/gatsby/src/commands/build-html.ts#L322-L387

Fix and test for this case incoming some time today

vladar commented 3 years ago

Published in gatsby@3.0.2