nextjs - 💡(How to fix) Fix Next.js 16.0.3: Build fails with React hooks errors on auto-generated pages (React 19.2) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#86146Fetched 2026-04-08 02:12:21
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Next.js 16.0.3 production build fails with TypeError: Cannot read properties of null (reading 'useState') when generating auto-generated pages (/_not-found, /_global-error). This is a regression from 16.0.0 which builds successfully with the same code.

Error Message

Error occurred prerendering page "/not-found". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: Cannot read properties of null (reading 'useState') at e (.next\server\chunks\ssr[root-of-the-server]__0238eb7a..js:1:6782) { digest: '569475980' } Export encountered an error on /_not-found/page: /_not-found, exiting the build. ⨯ Next.js build worker exited with code: 1 and signal: null

Root Cause

Next.js 16.0.3 production build fails with TypeError: Cannot read properties of null (reading 'useState') when generating auto-generated pages (/_not-found, /_global-error). This is a regression from 16.0.0 which builds successfully with the same code.

Fix Action

Workaround

Downgrade to Next.js 16.0.0 - Production build and dev server work perfectly with identical code.

# In package.json
"next": "^16.0.0"
"eslint-config-next": "^16.0.0"

Code Example

{
  "dependencies": {
    "next": "^16.0.3",
    "react": "^19.2.0",
    "react-dom": "^19.2.0"
  },
  "devDependencies": {
    "eslint-config-next": "^16.0.3",
    "typescript": "^5.9.2"
  }
}

---

export default {
  turbopack: {},
  reactCompiler: true,
  experimental: {
    turbopackFileSystemCacheForDev: true,
  },
  serverExternalPackages: ['@duckdb/node-api', 'msnodesqlv8', 'mssql']
};

---

rm -rf node_modules .next yarn.lock
   yarn install

---

yarn build

---

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useState')
    at e (.next\server\chunks\ssr\[root-of-the-server]__0238eb7a._.js:1:6782) {
  digest: '569475980'
}
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
  Next.js build worker exited with code: 1 and signal: null

---

TypeError: Cannot read properties of null (reading 'useContext')
    at ignore-listed frames {
  digest: '2522360787'
}

---

FATAL: An unexpected Turbopack error occurred
Turbopack Error: Failed to write app endpoint /page

A panic log has been written to %TEMP%\next-panic-*.log

---

# In package.json
"next": "^16.0.0"
"eslint-config-next": "^16.0.0"

---

Operating System:
  Platform: win32
  Version: Windows 11

Binaries:
  Node: 22.16.0
  npm: N/A
  Yarn: 1.22.22

Relevant Packages:
  next: 16.0.3
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.2

Next.js Config:
  output: N/A
  turbopack: enabled (default)
RAW_BUFFERClick to expand / collapse

Description

Next.js 16.0.3 production build fails with TypeError: Cannot read properties of null (reading 'useState') when generating auto-generated pages (/_not-found, /_global-error). This is a regression from 16.0.0 which builds successfully with the same code.

Environment

  • Next.js: 16.0.3
  • React: 19.2.0
  • React DOM: 19.2.0
  • Node.js: 22.16.0
  • OS: Windows 11
  • Package Manager: Yarn 1.22.22
  • Build Tool: Turbopack (default in 16.0.3)

Relevant package.json:

{
  "dependencies": {
    "next": "^16.0.3",
    "react": "^19.2.0",
    "react-dom": "^19.2.0"
  },
  "devDependencies": {
    "eslint-config-next": "^16.0.3",
    "typescript": "^5.9.2"
  }
}

next.config.js:

export default {
  turbopack: {},
  reactCompiler: true,
  experimental: {
    turbopackFileSystemCacheForDev: true,
  },
  serverExternalPackages: ['@duckdb/node-api', 'msnodesqlv8', 'mssql']
};

Steps to Reproduce

  1. Start with a working Next.js 16.0.0 project (React 19.2.0)
  2. Update package.json:
    • next: ^16.0.0^16.0.3
    • eslint-config-next: ^16.0.0^16.0.3
  3. Clean install:
    rm -rf node_modules .next yarn.lock
    yarn install
  4. Run production build:
    yarn build

Expected Behavior

Production build completes successfully, as it does on Next.js 16.0.0.

Actual Behavior

Build fails during static page generation on /_not-found:

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useState')
    at e (.next\server\chunks\ssr\[root-of-the-server]__0238eb7a._.js:1:6782) {
  digest: '569475980'
}
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null

Additional Error Variant: If NODE_ENV=development is manually set in .env (which violates Next.js best practices), the error occurs on /_global-error instead:

TypeError: Cannot read properties of null (reading 'useContext')
    at ignore-listed frames {
  digest: '2522360787'
}

Turbopack Dev Server Also Fails

Running yarn dev with Turbopack crashes immediately:

FATAL: An unexpected Turbopack error occurred
Turbopack Error: Failed to write app endpoint /page

A panic log has been written to %TEMP%\next-panic-*.log

What We've Verified

Clean dependency reinstall - Removed node_modules, .next, yarn.lock, reinstalled from scratch
No NODE_ENV in .env - Removed manual NODE_ENV setting per Next.js docs
No React version conflicts - yarn list react shows single React 19.2.0 instance
Not a monorepo - Simple Next.js App Router project, no nested dependencies
TypeScript passes - tsc --noEmit completes without errors
No custom error pages - No custom global-error.tsx or not-found.tsx files
Fresh .next cache - Multiple clean builds attempted

Workaround

Downgrade to Next.js 16.0.0 - Production build and dev server work perfectly with identical code.

# In package.json
"next": "^16.0.0"
"eslint-config-next": "^16.0.0"

Additional Context

  • The errors only occur on auto-generated Next.js pages (/_not-found, /_global-error)
  • All application routes, pages, and APIs work correctly in development on 16.0.0
  • Issue appears specific to React 19.2 + Next.js 16.0.3 combination
  • Related closed issue: #85668 (resolution was dependency cleanup, which we've done thoroughly)
  • No middleware or special routing configurations

Possibly Related Commits

This regression likely occurred in commits between 16.0.0 and 16.0.3 affecting:

  • React hooks handling in SSR/static generation
  • Auto-generated error page rendering
  • Turbopack page bundling

System Information

Operating System:
  Platform: win32
  Version: Windows 11

Binaries:
  Node: 22.16.0
  npm: N/A
  Yarn: 1.22.22

Relevant Packages:
  next: 16.0.3
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.2

Next.js Config:
  output: N/A
  turbopack: enabled (default)

extent analysis

TL;DR

Downgrade to Next.js 16.0.0 to resolve the production build failure caused by a regression in Next.js 16.0.3.

Guidance

  • Verify that the issue is specific to the combination of React 19.2.0 and Next.js 16.0.3 by checking if the error occurs with different versions.
  • Check the Next.js changelog and release notes for any mentions of changes to React hooks handling in SSR/static generation or auto-generated error page rendering.
  • Consider opening a new issue on the Next.js GitHub repository, referencing the closed issue #85668 and providing detailed reproduction steps.
  • If downgrading to Next.js 16.0.0 is not feasible, explore alternative workarounds, such as modifying the next.config.js file or adjusting the project's dependencies.

Example

No code snippet is provided as the issue is related to a specific version regression and not a code-specific problem.

Notes

The issue appears to be specific to the combination of React 19.2.0 and Next.js 16.0.3, and downgrading to Next.js 16.0.0 resolves the issue. However, this may not be a viable long-term solution, and further investigation is needed to identify the root cause and develop a more permanent fix.

Recommendation

Apply the workaround by downgrading to Next.js 16.0.0, as it has been verified to resolve the issue. This will allow for a temporary solution until a more permanent fix is developed.

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