Fixing “Application Error: A Client-Side Exception Has Occurred”
When deploying a web app—especially on platforms like Vercel, Netlify, or Render—you might see this generic page:
Application error: a client-side exception has occurred.
This means your frontend JavaScript crashed in the browser. Below is a practical guide to diagnose and resolve it.
Quick Triage (5–10 Minutes)
-
Open DevTools → Console and Network tabs. Note the first red error and its stack trace.
-
Reproduce locally in production mode. Many errors hide in development builds.
Bash -
If the error occurs only after deployment:
- Confirm all environment variables exist on your host.
- For Next.js, public vars must start with
NEXT_PUBLIC_
. - Clear browser cache, disable extensions, and reload.
Common Causes and Fixes
1. Accessing Browser-Only APIs During SSR (Next.js)
Symptom: window is not defined
, document is not defined
, or hydration mismatch.
Fix:
Tsx
Or disable SSR for a component:
Tsx
2. Unhandled Fetch or JSON Parse Errors
Symptom: Unexpected token < in JSON
or crashes on bad responses.
Fix:
Ts
3. Undefined Data or Props
Symptom: Cannot read properties of undefined (reading 'x')
.
Fix:
Ts
4. Environment Variable Mismatch
Symptom: Works locally, fails after deploy. Fixes:
- Re-enter variables in your hosting dashboard.
- Redeploy to refresh build cache.
- Prefix client-side variables with
NEXT_PUBLIC_
.
5. Hydration Mismatches (Next.js)
Symptom: “Text content does not match server-rendered HTML.” Fix:
- Avoid rendering random or time-based values on the server.
- Move them inside
useEffect
. - Ensure conditional rendering matches server and client output.
6. Compatibility Issues and Polyfills
If supporting older browsers, check your build target and ensure modern features (like optional chaining) are transpiled.
7. Add Error Boundaries (React/Next.js)
Prevent one broken component from crashing the whole app:
Tsx
In Next.js 13+, use an error.tsx
file per route segment.
8. Use Source Maps and Global Logging
Enable source maps to trace minified code:
Js
Capture uncaught errors early:
Ts
Deployment-Level Checks
- Inspect build logs for warnings or missing variables.
- Validate Edge/Serverless responses—bad JSON or headers can crash the client.
- Confirm base URLs are correct (no
localhost
left in config).
Summary
“Client-side exception” means your browser JavaScript failed. Fixes usually involve:
- Correcting SSR/client code separation.
- Handling network and data safely.
- Verifying environment variables.
- Adding error boundaries and logging.
With the above checkpoints, you can move from a blank error page to a stable, traceable, and production-ready deployment.