Skip to content

Build fails on Next.js 15.4.5 with TypeError: Cannot read properties of null (reading 'useContext') during prerendering of /404 #82366

Description

@jsdev-robin

Link to the code that reproduces this issue

https://github.com/vercel/turborepo/tree/main/examples/with-tailwind

To Reproduce

  1. Use Next.js 15.4.5
  2. Run npm install
  3. Run next build
  4. You will see:

TypeError: Cannot read properties of null (reading 'useContext') at p (...\.next\server\pages\_error.js:19:2590) Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error Export encountered an error on /_error: /404, exiting the build. ⨯ Next.js build worker exited with code: 1 and signal: null

Current vs. Expected behavior

next build should complete successfully and statically export all pages including /404 and /_error.

Actual:
Build fails with a runtime error during prerendering.

Provide environment information

Operating System: Windows 11 64-bit
Node.js Version: 20.12.2
npm Version: 10.5.0
Package Manager: npm
Next.js Version: 15.4.5
Hosting: Local

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

Suspected root cause: useContext called on null during _error.js or /404 rendering in static export

auto-install-peers warning likely unrelated, but present

I tested disabling the _error.tsx file, and build succeeds

Disabling "output": "standalone" does not fix the issue

NEXT-4720

Metadata

Metadata

Assignees

No one assigned

    Labels

    linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions