Gatsby, Prismic - error Building static HTML failed for path "/blog/"

Viewed 126

I have a website created using Gatsby v. 3.0.1 and Prismic CMS, and Github Actions for CI/CD. The build of the page on GH is triggered automatically every time content is added/edited on CMS.

Blog posts on the website are generated dynamically with gatsby-node.js createPage function:

  const blog = require.resolve(
    `./src/components/features/blog/post/PostDetails.tsx`
  );

  const result = await graphql(`
    {
      allPrismicBlogPost {
        edges {
          node {
            lang
            tags
            data {
              link {
                text
              }
            }
          }
        }
      }
    }
  `);

  result?.data?.allPrismicBlogPost?.edges?.forEach(({ node }) => {
    createPage({
      path: `/blog/${node?.data?.link?.text}/`,
      component: blog,
      context: {
        link: node?.data?.link?.text,
      },
    });
  });

Couple of days ago after adding a new blog post the build failed with following error:

  error Building static HTML failed for path "/blog/"

  SyntaxError:Unexpected number in JSON at position 183
  
  - JSON.parse
  
  - render-html.js:58 readPageData
    [website]/[gatsby]/dist/utils/worker/render-html.js:58:15
  
  - render-html.js:266 async _bluebird.default.map.concurrency
    [website]/[gatsby]/dist/utils/worker/render-html.js:266:24

Now every time I try to add new post the build fails, and the only way to fix this is to archive the post in Prismic. Weird thing is that this build fail doesn't happen if I edit already existing blog post, only when adding a new one.

I cannot reproduce the error locally, it only fails on Github build.

I've already looked through the blog post in order to find something that could've broken the build, like some unusual fields that weren't present in previous blog posts, reinstalled all packages, updated package-lock.json, added empty blog posts to see if this would work, looked through every file in /public folder to find some clue but nothing yet worked and the build still fails when adding new blog posts. Has anyone else had this issue and knows how to fix this?

Full stack trace: https://pastebin.com/VbLJZk3P

My package.json:

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "-": "^0.0.1",
    "@reduxjs/toolkit": "^1.5.0",
    "@types/react-redux": "^7.1.16",
    "@types/styled-components": "^5.1.9",
    "bootstrap": "^4.6.0",
    "dotenv": "^8.2.0",
    "gatsby": "^3.0.1",
    "gatsby-plugin-alias-imports": "^1.0.5",
    "gatsby-plugin-force-trailing-slashes": "^1.0.5",
    "gatsby-plugin-gatsby-cloud": "^2.0.0",
    "gatsby-plugin-gdpr-cookies": "^2.0.8",
    "gatsby-plugin-graphql-codegen": "^3.1.0",
    "gatsby-plugin-manifest": "^3.0.0",
    "gatsby-plugin-offline": "^4.0.0",
    "gatsby-plugin-react-helmet": "^4.0.0",
    "gatsby-plugin-react-svg": "^3.0.0",
    "gatsby-plugin-robots-txt": "^1.6.10",
    "gatsby-plugin-sass": "^4.1.0",
    "gatsby-plugin-sharp": "^3.0.0",
    "gatsby-plugin-sitemap": "^4.10.0",
    "gatsby-plugin-social9-socialshare": "^1.0.5",
    "gatsby-source-filesystem": "^3.0.0",
    "gatsby-source-prismic": "^3.3.4",
    "gatsby-transformer-sharp": "^3.0.0",
    "graphql": "^15.5.0",
    "graphql-cli": "3.0.14",
    "graphql-request": "^3.4.0",
    "prismic-reactjs": "^1.3.3",
    "prop-types": "^15.7.2",
    "react": "^17.0.1",
    "react-bootstrap": "^1.5.2",
    "react-cookie-consent": "^6.2.4",
    "react-dom": "^17.0.1",
    "react-glider": "^2.1.1",
    "react-helmet": "^6.1.0",
    "react-is": "^17.0.2",
    "react-media": "^2.0.0-rc.1",
    "react-redux": "^7.2.2",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "sass": "^1.32.8",
    "styled-components": "^5.2.3",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@types/node": "^14.14.35",
    "@types/react": "^17.0.3",
    "@types/react-dom": "^17.0.2",
    "@types/react-helmet": "^6.1.0",
    "@types/uuid": "^8.3.4",
    "eslint-config-prettier": "^8.3.0",
    "prettier": "^2.2.1",
    "tsconfig-paths-webpack-plugin": "^3.5.1",
    "typescript": "^4.2.3"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "npm run type-check && npm run lint",
    "lint": "eslint . --ext .ts,.tsx",
    "type-check": "tsc --pretty"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}
0 Answers
Related