PageAI full logo

Fixing common issues and errors

Updated on

Generation issues

Network failed / ERR_NETWORK and similar

This can happen if you can't reach the PageAI API while generating a codebase. Steps to resolve:

  1. Restart your computer :-)
  2. Open pageai.pro/api/og. Check if you see an image; if not, you cannot reach the PageAI API.
  3. Try a different network; generate a codebase while connected to a mobile hotspot
  4. Try to turn off VPN/Firewalls if any are active
  5. If possible, try generating on a separate device

Build issues

TypeError: Cannot read properties of null (reading 'useContext')

Or sometimes:

  • Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
  • Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error

This happens if you have 2 versions of React installed. To fix this, run:

npm install react@latest react-dom@latest

Using Turborepo

If you are using a monorepo setup with Turborepo, it's also possible that you have multiple versions of React installed depending on the apps you have within.

Steps to resolve:

  1. Ensure all versions of React are the same across all your “apps” in the turborepo.

Look closely at the package.json files of all your apps and ensure that the versions of React and React-DOM are the same. Even this can cause issues:

"react": "18.2.0" # in one app and
"react": "^18.2.0" # in another app

might result in different versions being installed.

If you are still having issues, try the following:

  1. Make Next/React nohoist (see this discussion or this StackOverflow answer or Turborepo's docs)

  2. Make Next/React a peer dependency Discussion

  3. Install Next/React at the root of the Turborepo

Blog and MDX issues

No blog posts are being generated

Usually, this means there is a syntax error in one of the blog posts. To fix this, check the console for errors and correct the markdown in the file (see below for common errors).

Invalid markdown in 1 documents

This error occurs when a blog post has invalid markdown. To fix this, check the error in the console and correct the markdown in the file.

Usually, this is either a YAML issues, for example, not using > for multiline strings, or an issue with HTML/JSX in the content. Here's how to correctly use multiline strings in YAML:

---
...

description: >
This is a multiline string
that will be rendered as a single line

---

Type 'string' is not assignable to type 'Toc'

Make sure you have the correct type for the toc field in contentlayer.config.ts (json)

contentlayer.config.ts
-  toc: { type: 'string', resolve: (doc) => extractTocHeadings(doc.body.raw) },
+  toc: { type: 'json', resolve: (doc) => extractTocHeadings(doc.body.raw) },