Current versus Expected Behavior
Current behavior:
-
In development, I encounter this error:
Hydration failed because the server rendered HTML didn't match the client.
-
In production, after deploying to Vercel, I get this prerendering error:
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
Expected behavior:
The application should render correctly both in development and production without hydration errors or prerendering issues.
Code, Configuration, and Steps to Reproduce
-
Repository:
-
Steps to reproduce:
-
Run the project locally in development mode using
npm run dev
. -
Open the main register page to see the hydration error.
-
Deploy the project to Vercel and observe the prerendering issue in production.
-
Project Information
-
Framework: Next.js
-
Environment:
-
Local: Node.js version v22.12.0, OS MacOS 10.15
-
Production: Deployed on Vercel
-
-
Vercel Configuration:
-
Target: Production
-
Build Command:
next build
-
Output Directory:
.next
-
Additional Notes
I suspect the hydration error is caused by the use of document
or window
in server-side code (SSR). I’m unsure how to resolve this properly or prevent the prerendering issue in production.