nextjs - ✅(Solved) Fix `next build` fails while prerendering internal /_global-error route that does not exist in the app [3 pull requests, 17 comments, 13 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#87719Fetched 2026-04-08 02:06:26
View on GitHub
Comments
17
Participants
13
Timeline
47
Reactions
0

Error Message

Error occurred prerendering page "/_global-error". Read more: https://nextjs.org/docs/messages/prerender-error Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js. Export encountered an error on /_global-error/page: /_global-error, exiting the build.

Fix Action

Fixed

PR fix notes

PR #7: Phase 6g: Accessibility audit, build fix, review comment fixes, and real MCP server integration

Description (problem / solution / changelog)

Completes Phase 6g (Integration Testing + Polish) — the final sub-phase of Phase 6. Comprehensive accessibility audit of all 16 page components, fixing 15 issues across 8 files, a critical build fix for Next.js 16, fixes for 6 review comments addressing correctness, performance, and HTML validity issues, and real MCP server integration per the physicsandmathmCP.md configuration document.

Build fix

  • global-error.tsx: Removed all CSS class dependencies (bg-mesh, antialiased, and className="dark") that triggered Next.js 16's known InvariantError: Expected workUnitAsyncStorage during /_global-error prerendering (<a href="https://github.com/vercel/next.js/issues/87719">vercel/next.js#87719</a>). Now uses inline styles only + role="alert".

Favicon fix

  • favicon.ico: Replaced the old globe icon with a new atom/neural-network motif ICO (teal→gold gradient, orbital rings, neural nodes) matching the new logo branding. The old src/app/favicon.ico was overriding the SVG metadata config since Next.js auto-discovers app/favicon.ico.

Bug fixes

  • queries.ts: Fixed d.status === "completed""concluded" — debate wins were never being counted because the actual status value is "concluded". Also optimized debate-win calculation from O(D×M) to O(M+D) by pre-grouping messages by debateId.
  • ForumsClient.tsx: Replaced nested <Link> inside <Link> (invalid HTML) with <span>, since the outer card already navigates to the forum.
  • playwrightBrowser.ts: Fixed accessibility snapshot returning null for root BODY element by mapping BODY→"document" role and traversing children of unrecognized elements (DIV, SPAN, etc.) so the tree is populated.
  • tools/status route: Notebook status now checks python3 availability and reports correct executionMode (subprocess/gemini/simulated) instead of always reporting as available.

Real MCP server integration

Updated MCP tool routes to use real MCP server binaries per the physicsandmathmCP.md configuration document, replacing Gemini-only fallback behavior:

  • PsiAnimator-MCP: Added as a new MCP server for quantum visualization. The quantum route now tries PsiAnimator first (psianimator-mcp), then falls back to scicomp-quantum-mcp, then Gemini. PsiAnimator workflows support create_quantum_stateevolve_statevisualize_state multi-step pipelines. Added to sidebar, header dropdown, MCP dashboard, and status route.
  • PDG route: Updated command from particlephysics-mcp to pp-mcp-server and tool call from get_particle to search_particle to match the real ParticlePhysics MCP Server binary interface per the document.
  • mcpClient.ts: Added psianimator-mcp to the MCP server registry with proper command configuration and uvx install fallback support.
  • Install scripts: Added mcp:install:psianimator script; updated all install commands to use uvx fallbacks per document recommendations.
  • Status route: Reports PsiAnimator availability separately for the quantum route, showing which MCP backend is active.
  • Agent prompt: Updated with PsiAnimator priority, correct tool names, and install commands for all MCP servers.
  • MCP Dashboard: Added PsiAnimator card with status indicator and "Try It" examples for quantum state creation and visualization.

Accessibility fixes

  • Sidebar.tsx: aria-expanded + aria-label on collapsible SidebarSection buttons; aria-label on all 4 platform stat elements
  • ForumsClient.tsx / ForumThreadsClient.tsx: aria-label on upvote buttons with dynamic voted/not-voted state; aria-label on "New Thread" toggle
  • formalism/page.tsx: role="tab", aria-selected, aria-label on tab buttons
  • AuditClient.tsx: Converted <div onClick> to accessible pattern with role="button", tabIndex={0}, aria-expanded, aria-label, and keyboard handler (Enter/Space)
  • tools/page.tsx, tools/mcp/page.tsx: aria-label on tool selector buttons

CSS

  • Tooltip pseudo-element: added z-index: 50 to prevent stacking issues; :focus selector alongside :hover for keyboard accessibility
<!-- START COPILOT CODING AGENT TIPS -->

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Changed files

  • .github/copilot-instructions.md (modified, +485/-9)
  • .gitignore (modified, +3/-0)
  • README.md (modified, +743/-34)
  • TECHNICAL_SPECIFICATION.md (modified, +376/-119)
  • next.config.ts (modified, +6/-1)
  • package-lock.json (modified, +45/-0)
  • package.json (modified, +6/-0)
  • public/favicon.svg (added, +19/-0)
  • public/logo-icon.svg (added, +25/-0)
  • public/logo.svg (added, +43/-0)
  • src/app/agents/AgentsClient.tsx (modified, +37/-8)
  • src/app/agents/[id]/page.tsx (modified, +18/-7)
  • src/app/agents/page.tsx (modified, +19/-2)
  • src/app/api/audit/stream/route.ts (modified, +38/-24)
  • src/app/api/tools/math/route.ts (modified, +105/-33)
  • src/app/api/tools/molecular/route.ts (modified, +98/-38)
  • src/app/api/tools/neural/route.ts (modified, +90/-39)
  • src/app/api/tools/notebook/route.ts (modified, +139/-32)
  • src/app/api/tools/pdg/route.ts (modified, +71/-37)
  • src/app/api/tools/playwright/route.ts (modified, +158/-72)
  • src/app/api/tools/quantum/route.ts (modified, +185/-41)
  • src/app/api/tools/status/route.ts (added, +184/-0)
  • src/app/api/verifications/[id]/stream/route.ts (modified, +10/-2)
  • src/app/audit/AuditClient.tsx (modified, +5/-0)
  • src/app/debates/DebatesClient.tsx (modified, +79/-24)
  • src/app/debates/[id]/page.tsx (modified, +7/-7)
  • src/app/favicon.ico (modified, +0/-0)
  • src/app/formalism/page.tsx (modified, +9/-6)
  • src/app/forums/ForumsClient.tsx (modified, +43/-8)
  • src/app/forums/[slug]/ForumThreadsClient.tsx (modified, +6/-3)
  • src/app/forums/[slug]/threads/[threadId]/page.tsx (modified, +5/-5)
  • src/app/global-error.tsx (added, +64/-0)
  • src/app/globals.css (modified, +72/-69)
  • src/app/knowledge/KnowledgeClient.tsx (modified, +11/-3)
  • src/app/layout.tsx (modified, +13/-0)
  • src/app/not-found.tsx (added, +21/-0)
  • src/app/page.tsx (modified, +10/-10)
  • src/app/tools/mcp/page.tsx (added, +494/-0)
  • src/app/tools/page.tsx (modified, +4/-3)
  • src/app/verification/VerificationClient.tsx (modified, +8/-8)
  • src/components/Breadcrumbs.tsx (added, +56/-0)
  • src/components/Header.tsx (modified, +50/-5)
  • src/components/Sidebar.tsx (modified, +156/-54)
  • src/lib/mcpClient.ts (added, +445/-0)
  • src/lib/playwrightBrowser.ts (added, +498/-0)
  • src/lib/queries.ts (modified, +141/-8)

PR #48: review: codebase hardening — conventions, architecture, security

Description (problem / solution / changelog)

Résumé

Audit complet du codebase orienté conventions, architecture et sécurité. 11 commits atomiques, zéro nouvelle dépendance.

  • Nommage : renommage des callbacks single-letter, ajout d'interfaces props nommées, suppression des any, noms de variables sémantiques
  • Constantes : extraction des magic strings en ROLES, BOOKING_STATUSES, AUTH_ERROR_CODES
  • Routes : normalisation FR→EN (/connexion/sign-in, /inscription/sign-up, /reservations/bookings, /gerant/manager)
  • Architecture : déplacement de auth-guards.ts et LogoutButton.tsx du feature layer vers le shared layer (correction des violations de boundary)
  • Sécurité : ajout du guard requireAdmin() sur toutes les server actions establishments
  • Typed routes : activation de experimental.typedRoutes dans Next.js, correction d'un lien cassé détecté par le type check
  • Langue : traduction de tous les commentaires et données de seed en anglais (l'UI reste en français)
  • Error boundary : ajout de global-error.tsx comme fallback racine
  • Rules : ajout de 2 nouvelles guidelines (convention linguistique, autorisation), correction des globs sur 10 rules existantes (il manquait app/)

Fichiers impactés

  • 65 fichiers modifiés au total (code applicatif + rules Claude Code)
  • 9 fichiers créés (constantes, types, pages, error boundary, 2 rules)
  • 2 fichiers déplacés (feature → shared)
  • 2 dossiers renommés
  • 0 nouvelle dépendance

Vérifications effectuées

  • tsc --noEmit : clean
  • ESLint : 0 erreur, 0 warning
  • next build : compile OK (prerendering /_global-error échoue — bug Next.js #87719, pré-existant)

Plan de test

  • Vérifier que /sign-in et /sign-up fonctionnent (anciennes routes /connexion et /inscription)
  • Vérifier que les actions admin (create/update/delete establishment) rejettent un utilisateur non-admin
  • Vérifier que le seed fonctionne (bun run db:seed)
  • Vérifier que les rules Claude Code se chargent correctement sur les fichiers app/

🤖 Generated with Claude Code

Changed files

  • .claude/rules/00-architecture/0-architecture.md (modified, +2/-1)
  • .claude/rules/01-standards/1-accessibility.md (modified, +1/-1)
  • .claude/rules/01-standards/1-clean-code.md (modified, +4/-3)
  • .claude/rules/01-standards/1-language-convention.md (added, +24/-0)
  • .claude/rules/01-standards/1-naming-conventions.md (modified, +1/-1)
  • .claude/rules/02-programming-languages/2-typescript.md (modified, +1/-1)
  • .claude/rules/03-frameworks-and-libraries/3-react.md (modified, +2/-1)
  • .claude/rules/03-frameworks-and-libraries/3-tailwind-v4.md (modified, +1/-1)
  • .claude/rules/08-domain-specific-rules/8-authorization.md (added, +17/-0)
  • .claude/rules/08-domain-specific-rules/8-error-handling.md (modified, +1/-1)
  • .claude/rules/08-domain-specific-rules/8-ui-feedback.md (modified, +1/-1)
  • app/db-viewer/page.tsx (modified, +11/-11)
  • app/global-error.tsx (added, +24/-0)
  • app/sign-in/page.tsx (renamed, +0/-0)
  • app/sign-up/page.tsx (renamed, +0/-0)
  • app/suites/[id]/page.tsx (added, +4/-0)
  • app/unauthorized.tsx (modified, +1/-1)
  • docs/logs/2026-03-19_codebase-cleanup.md (added, +201/-0)
  • next.config.mjs (modified, +3/-0)
  • proxy.ts (modified, +9/-8)
  • src/components/layout/Header.tsx (modified, +3/-3)
  • src/components/layout/LogoutButton.tsx (renamed, +0/-0)
  • src/components/ui/input.tsx (modified, +4/-4)
  • src/components/ui/label.tsx (modified, +6/-6)
  • src/config/booking-statuses.ts (added, +6/-0)
  • src/config/roles.ts (added, +7/-0)
  • src/features/auth/actions/login.ts (modified, +5/-3)
  • src/features/auth/actions/register.ts (modified, +3/-2)
  • src/features/auth/components/LoginForm.tsx (modified, +6/-4)
  • src/features/auth/components/RegisterForm.tsx (modified, +6/-4)
  • src/features/auth/lib/auth-error-codes.ts (added, +5/-0)
  • src/features/auth/types/auth.types.ts (modified, +1/-1)
  • src/features/bookings/actions/cancel-booking.ts (added, +8/-0)
  • src/features/bookings/actions/create-booking.ts (renamed, +3/-3)
  • src/features/bookings/components/BookingForm.tsx (renamed, +1/-1)
  • src/features/bookings/components/BookingList.tsx (added, +10/-0)
  • src/features/bookings/queries/get-available-suites.ts (renamed, +1/-1)
  • src/features/bookings/queries/get-bookings.ts (added, +6/-0)
  • src/features/db-viewer/components/DataTable.tsx (modified, +15/-11)
  • src/features/db-viewer/components/SchemaTable.tsx (modified, +13/-9)
  • src/features/db-viewer/components/TypeBadge.tsx (modified, +7/-3)
  • src/features/db-viewer/lib/extract-columns.ts (modified, +10/-15)
  • src/features/establishments/actions/create-establishment.ts (modified, +4/-2)
  • src/features/establishments/actions/delete-establishment.ts (modified, +4/-3)
  • src/features/establishments/actions/update-establishment.ts (modified, +1/-0)
  • src/features/establishments/queries/get-establishment-by-id.ts (modified, +2/-2)
  • src/features/establishments/queries/has-active-bookings.ts (modified, +5/-3)
  • src/features/reservations/actions/cancel-reservation.ts (removed, +0/-8)
  • src/features/reservations/components/ReservationList.tsx (removed, +0/-10)
  • src/features/reservations/queries/get-reservations.ts (removed, +0/-6)
  • src/features/suites/components/SuiteDetail.tsx (modified, +5/-1)
  • src/lib/auth-guards.ts (renamed, +6/-5)
  • src/lib/auth.ts (modified, +2/-1)
  • src/lib/db/schema.ts (modified, +8/-6)
  • src/lib/db/seed.ts (modified, +11/-9)
  • src/types/role.types.ts (added, +1/-0)

PR #577: fix: Next.js 16 global-error prerender breaks SST deploy

Description (problem / solution / changelog)

Summary

  • Remove NODE_ENV=development from .env.example — this setting overrides Next.js's internal NODE_ENV=production during next build, causing a useContext null crash when Next.js 16 prerenders the internal /_global-error route. Next.js manages NODE_ENV automatically.
  • Add .open-next/ to .gitignore (OpenNext build artifacts)

Local action required

Developers should remove NODE_ENV=development from their local .env file. Also delete apps/web/app/global-error.tsx if it exists locally (it was never committed but may have been created as a workaround).

Context

Next.js 16 always prerenders /_global-error. When NODE_ENV=development is set during next build, React context initialization fails during that prerender, crashing the build with:

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

See: https://github.com/vercel/next.js/issues/87719

Fixes #576

🤖 Generated with Claude Code

<!-- coverage-summary-start -->

Test Coverage

PackageCoverageDelta
core84.0%+0.0%
shared94.7%+0.0%
ingestion77.8%+0.0%
evals43.8%+0.0%
slack75.9%+0.0%
web68.5%+0.0%
<!-- coverage-summary-end -->

Changed files

  • .env.example (modified, +0/-1)
  • .gitignore (modified, +1/-0)
  • package.json (modified, +2/-1)
  • pnpm-lock.yaml (modified, +23/-13)

Code Example

os: arch-linux
node: v24.4.1
pnpm: 10.26.1
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/bnjmnjrk/next-build-bug

To Reproduce

  1. run: pnpx next build

Current vs. Expected behavior

I expected the build to be successful, but instead I got:

▲ Next.js 16.1.1 (Turbopack)

Creating an optimized production build ... ✓ Compiled successfully in 1622.4ms ✓ Finished TypeScript in 1291.8ms ✓ Collecting page data using 7 workers in 344.7ms Error occurred prerendering page "/global-error". Read more: https://nextjs.org/docs/messages/prerender-error Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js. at M (.next/server/chunks/ssr/[root-of-the-server]__03cd63cf..js:1:95629) at bM (.next/server/chunks/ssr/[root-of-the-server]__03cd63cf._.js:4:7728) Export encountered an error on /_global-error/page: /_global-error, exiting the build. ⨯ Next.js build worker exited with code: 1 and signal: null

Provide environment information

os: arch-linux
node: v24.4.1
pnpm: 10.26.1

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

create-next-app

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

next build (local)

Additional context

project setup was: pnpm create next-app@latest my-app --yes

extent analysis

TL;DR

The most likely fix is to update Next.js to a version where the workUnitAsyncStorage bug is resolved or apply a workaround to bypass the prerendering error.

Guidance

  • Check the Next.js documentation and GitHub issues for any known bugs related to workUnitAsyncStorage and prerendering errors in version 16.1.1.
  • Verify if the issue persists when running the build with a different Node.js version, as the error might be specific to Node.js v24.4.1.
  • Consider temporarily disabling prerendering for the _global-error page to work around the issue.
  • Review the project setup and configuration to ensure that it aligns with the latest recommendations for create-next-app and Next.js.

Example

No specific code snippet can be provided without further information about the project's codebase.

Notes

The provided information suggests a bug in Next.js, and resolving the issue might require waiting for an update or applying a workaround. The Node.js version and project setup might also contribute to the error.

Recommendation

Apply a workaround to bypass the prerendering error, as the issue seems to be related to a bug in Next.js 16.1.1, and updating to a fixed version might not be immediately possible.

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