I get this error only with turborepo: Error occurred prerendering page "/404"
Answered
Anay-208 | Ping on replies posted this in #help-forum

I recently updated to next 15, and haven't modified the 404 page.
However, I'm getting this error for some reason while building the app
However, I'm getting this error for some reason while building the app
▲ Next.js 15.1.2
- Environments: .env
Creating an optimized production build ...
SyntaxError: Expected property name or '}' in JSON at position 182
at JSON.parse (<anonymous>)
SyntaxError: Expected property name or '}' in JSON at position 182
at JSON.parse (<anonymous>)
SyntaxError: Expected property name or '}' in JSON at position 182
at JSON.parse (<anonymous>)
✓ Compiled successfully
✓ Linting and checking validity of types
SyntaxError: Expected property name or '}' in JSON at position 182
at JSON.parse (<anonymous>)
⚠ Using edge runtime on a page currently disables static generation for that page
✓ Collecting page data
[TypeError: Cannot read properties of null (reading 'useContext')]
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
Answered by Anay-208 | Ping on replies
https://github.com/vercel/turborepo/issues/9335
i found this, and this reply helped.
I just switched to pnpm after this, as I believe it'd be better for turborepo(and nextjs-forum, the bot is using it)
i found this, and this reply helped.
I just switched to pnpm after this, as I believe it'd be better for turborepo(and nextjs-forum, the bot is using it)

24 Replies

I honestly don't know what to even send, however, I'm sending 404 file

I've already checked the nextjs prerender page, which didn't help

Also tried deleting
not-found.tsx

yes this is something that happened to me aswell when i migrated a app to next15
its not actually the 404 page itself
it just says that the error happened on 404 because while prerendering a dynamic route for example, and failing, nextjs will automatically reroute to a 404 and throw the error there
so what u can do is slowly check everywhere where u have dynamic data and use useContext
cause thats where the error is coming from

@gin so what u can do is slowly check everywhere where u have dynamic data and use useContext

I deleted all the routes where there is dynamic data. The error still persists

I tried it in another app, where I just have a hello world homepage. same error

Chub mackerel
I guess there is should be a issue in your
.env/next.config.js

-# next.config.mjs
import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
// (when running the application with `next dev`), for more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === 'development') {
await setupDevPlatform();
}
// import type { NextConfig } from "next";
// const nextConfig: NextConfig = {
/** @type {import('next').NextConfig} */
const nextConfig = {
/* config options here */
};
export default nextConfig;
I'll try removing setupDevPlatform & see
nope, still same error

So I also tried creating another app, where it works perfectly fine.
I used the exact same files from the old project(including package.json) in the new project, but I still get the error on old project.
I just want to find the cause for the error
I used the exact same files from the old project(including package.json) in the new project, but I still get the error on old project.
I just want to find the cause for the error

So I found something interesting.
I basically have a turborepo, and I only get this error when I add that folder path to my
workspaces
in the repo root package.json
this was my repo root
Once I added
package.json
:{
"name": "package",
"scripts": {
"migrate": "turbo run migrate"
},
"devDependencies": {
"turbo": "^2.3.3"
},
"packageManager": "npm@8.5.0",
"workspaces": [
"apps/www",
"packages/*"
]
}
Once I added
apps/test
, I started getting the error on that dir
https://github.com/vercel/turborepo/issues/9335
i found this, and this reply helped.
I just switched to pnpm after this, as I believe it'd be better for turborepo(and nextjs-forum, the bot is using it)
i found this, and this reply helped.
I just switched to pnpm after this, as I believe it'd be better for turborepo(and nextjs-forum, the bot is using it)

Answer
i had the same issues with turbopack aswell
cool that u found a solution

I was too lazy to solve this with npm so switched to pnpm