nextjs - 💡(How to fix) Fix Next.js 16 canary.7: useContext null during /_global-error SSR prerender (build fails) [1 comments, 2 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#84994Fetched 2026-04-08 02:17:47
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Next.js 16.0.0-canary.7 fails to build due to useContext returning null during SSR prerendering of /_global-error page, even with minimal/no custom error components.

Error Message

Error occurred prerendering page "/_global-error". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
    at B (.next/server/chunks/3077.js:11:187105) {
  digest: '4119382757'
}
Export encountered an error on /_global-error/page: /_global-error, exiting the build.

Root Cause

Error occurs in Next.js Link component internals (AppRouterContext is null during SSR):

.next/server/chunks/3077.js:11:187105

This is Next.js framework code, not application code. The error is in how Next.js handles context during static generation of error pages.

Fix Action

Fix / Workaround

Workaround Needed

Code Example

Error occurred prerendering page "/_global-error". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
    at B (.next/server/chunks/3077.js:11:187105) {
  digest: '4119382757'
}
Export encountered an error on /_global-error/page: /_global-error, exiting the build.

---

// src/app/global-error.tsx
'use client';

export const dynamic = "force-dynamic";

export default function GlobalError({ error, reset }) {
  return (
    <div>
      <h1>Error</h1>
      <button onClick={reset}>Try Again</button>
    </div>
  );
}

---

.next/server/chunks/3077.js:11:187105
RAW_BUFFERClick to expand / collapse

Bug Report: Next.js 16 Canary SSR Prerender useContext Null Error

Summary

Next.js 16.0.0-canary.7 fails to build due to useContext returning null during SSR prerendering of /_global-error page, even with minimal/no custom error components.

Environment

  • Next.js: 16.0.0-canary.7
  • React: 19.2.0 (stable)
  • Node.js: 20.19.5
  • Package Manager: npm 10.9.2
  • OS: macOS (Darwin 24.6.0)
  • Build Mode: Production (next build --webpack)

Error Message

Error occurred prerendering page "/_global-error". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
    at B (.next/server/chunks/3077.js:11:187105) {
  digest: '4119382757'
}
Export encountered an error on /_global-error/page: /_global-error, exiting the build.

Reproduction Steps

  1. Create Next.js 16 canary.7 project with React 19.2.0
  2. Use next build --webpack (OpenNext Cloudflare adapter requirement)
  3. Add custom global-error.tsx with 'use client' and export const dynamic = "force-dynamic"
  4. Run build

Minimal Reproduction:

// src/app/global-error.tsx
'use client';

export const dynamic = "force-dynamic";

export default function GlobalError({ error, reset }) {
  return (
    <div>
      <h1>Error</h1>
      <button onClick={reset}>Try Again</button>
    </div>
  );
}

Behavior

  • Expected: Build succeeds (global-error should not prerender with force-dynamic)
  • Actual: Build fails with useContext null error during prerendering
  • Surprising: Error persists even with NO custom global-error.tsx (Next.js default fails)

Investigation

Tested exhaustively:

  • ✅ Removed all context providers from custom global-error
  • ✅ Used inline styles only (no imported components)
  • ✅ Added export const dynamic = "force-dynamic"
  • ✅ Deleted custom global-error.tsx entirely (Next.js default still fails)
  • ✅ Changed <a> to <button> (eliminate Next.js Link)
  • ✅ Removed deprecated config options (swcMinify, eslint)

Result: Error persists in ALL cases

Root Cause

Error occurs in Next.js Link component internals (AppRouterContext is null during SSR):

.next/server/chunks/3077.js:11:187105

This is Next.js framework code, not application code. The error is in how Next.js handles context during static generation of error pages.

Related Issues

  • #79427: Similar useContext null with Turbopack in Next.js 15.3.2 (reportedly fixed in 15.5.1-canary.4)
  • #65447: Error prerendering /_not-found with pageExtensions
  • #55462: Root layout errors not triggering global-error.tsx

Additional Context

Project Type: Large application (2,576+ TypeScript files) Use Case: Cloudflare Workers deployment via OpenNext adapter Migration: From Next.js 14.2.33 → 16.0.0-canary.7

Next.js 16 Breaking Changes Fixed:

  • Static runtime config (no conditional exports)
  • Client Components with route config (commented out)
  • Deprecated config options removed
  • 85% migration complete, blocked only by this error

Expected Resolution

Since Issue #79427 indicates a fix exists in later canaries for Next.js 15, likely one of:

  1. Fix will appear in Next.js 16.0.0-canary.8+
  2. Fix requires React 19.3.0 (not yet released)
  3. Different root cause specific to Next.js 16

Workaround Needed

For production deployment with Next.js 16 beta, need way to:

  • Disable /_global-error prerendering entirely, OR
  • Skip error page static generation, OR
  • Use different error boundary approach

Links

extent analysis

TL;DR

  • The most likely fix or workaround is to disable _global-error prerendering entirely or skip error page static generation until a fix is available in a later Next.js 16 canary version.

Guidance

  • Investigate the possibility of disabling _global-error prerendering using Next.js configuration options or by modifying the getStaticPaths method for the error page.
  • Consider using a different error boundary approach that does not rely on the _global-error page being prerendered.
  • Review the related issues (#79427, #65447, #55462) to see if any of the fixes or workarounds mentioned can be applied to this case.
  • Keep an eye on the Next.js 16 canary releases for a fix, as it is likely that this issue will be addressed in a future version.

Example

  • No specific code example can be provided without more information on the custom global-error.tsx component and the Next.js configuration.

Notes

  • The root cause of the issue is related to how Next.js handles context during static generation of error pages, specifically with the AppRouterContext being null during SSR.
  • The issue persists even with no custom global-error.tsx component, suggesting that it is a problem with the Next.js framework code.

Recommendation

  • Apply a workaround, such as disabling _global-error prerendering or using a different error boundary approach, until a fix is available in a later Next.js 16 canary version. This is because the issue is likely to be addressed in a future version, and a workaround can provide a temporary solution for production deployment.

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