nextjs - 💡(How to fix) Fix Next 16.2.4: next build crashes prerendering /_global-error with TypeError: Cannot read properties of null (reading 'useContext') [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#93011Fetched 2026-04-20 11:58:24
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2closed ×1labeled ×1locked ×1

next build on a fresh [email protected] scaffold (with React 19.2.4) crashes while prerendering the built-in /_global-error route:

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

The failure is inside Next's own bundled chunk, not user code. It reproduces with both Turbopack and Webpack, and with or without a user-provided app/global-error.tsx.

Pinning [email protected] + [email protected] resolves it, so this appears to be fixed on canary but not yet in any stable 16.2.x.

Error Message

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

Root Cause

next build on a fresh [email protected] scaffold (with React 19.2.4) crashes while prerendering the built-in /_global-error route:

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

The failure is inside Next's own bundled chunk, not user code. It reproduces with both Turbopack and Webpack, and with or without a user-provided app/global-error.tsx.

Pinning [email protected] + [email protected] resolves it, so this appears to be fixed on canary but not yet in any stable 16.2.x.

Fix Action

Fix / Workaround

Backport the canary fix(es) to a 16.2.x patch, or cut a new stable that includes them, so users on stable don't have to pin canary to unblock a fresh scaffold.

Code Example

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

---

pnpm dlx create-next-app@16.2.4 repro --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-pnpm
cd repro
pnpm build
RAW_BUFFERClick to expand / collapse

Summary

next build on a fresh [email protected] scaffold (with React 19.2.4) crashes while prerendering the built-in /_global-error route:

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

The failure is inside Next's own bundled chunk, not user code. It reproduces with both Turbopack and Webpack, and with or without a user-provided app/global-error.tsx.

Pinning [email protected] + [email protected] resolves it, so this appears to be fixed on canary but not yet in any stable 16.2.x.

Verification

Reproduce

pnpm dlx [email protected] repro --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-pnpm
cd repro
pnpm build

Expected: successful build. Actual: build fails with the useContext TypeError during /_global-error prerender.

Downgrading next and eslint-config-next to 16.3.0-canary.2 (no other changes) makes the same command succeed.

Environment

  • next: 16.2.4 (broken) / 16.3.0-canary.2 (working)
  • react / react-dom: 19.2.4
  • node: v25
  • pnpm: 9
  • OS: Ubuntu 24.04 (Linux 6.8)

Ask

Backport the canary fix(es) to a 16.2.x patch, or cut a new stable that includes them, so users on stable don't have to pin canary to unblock a fresh scaffold.

extent analysis

TL;DR

The issue can be resolved by upgrading to [email protected] and [email protected], which includes the fix for the useContext TypeError.

Guidance

  • The error occurs due to a bug in the next package, specifically in the prerendering of the built-in /_global-error route.
  • To verify the issue, run pnpm build on a fresh [email protected] scaffold and check for the TypeError: Cannot read properties of null (reading 'useContext') error.
  • As a temporary workaround, users can pin [email protected] and [email protected] to unblock their builds.
  • The issue is not related to user code, but rather a problem within Next's own bundled chunk.

Example

No code snippet is necessary, as the issue is related to a specific version of the next package.

Notes

The fix is currently only available in the 16.3.0-canary.2 version of next and eslint-config-next. A backport to a 16.2.x patch or a new stable release is needed to make the fix available to users on the stable channel.

Recommendation

Apply the workaround by pinning [email protected] and [email protected], as this is the only currently available solution that includes the fix for the useContext TypeError.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING