Published , Last updated
If you’ve encountered the error message:
"Application error: a client-side exception has occurred while loading www.example.com (see the browser console for more information)"
you’re not alone. This is a common JavaScript error that typically appears in Next.js, React, or Vercel-hosted applications when something breaks on the client-side (i.e., in the browser).
In this blog post, we’ll cover:
This error message is a generic client-side crash message. It means:
The application loaded, but A JavaScript error occurred in the browser, Causing React to break and stop rendering the page.
It’s common with frameworks like Next.js, Vite, or React SPA apps when client-side interactivity goes wrong.
Here are the top reasons this error happens, especially in production:
'use client'
Directive in App Router (Next.js)If you’re using Next.js App Router and using hooks like useState
, useEffect
, or useRouter
in a component without the 'use client'
directive at the top, it will crash.
Fix:
Add this at the top of your component file:
'use client';
Accessing a variable or property that doesn't exist can throw a client-side exception.
Example (Bad):
<p>{article.title}</p> // Throws error if article is undefined
Fix:
Use optional chaining or a fallback:
<p>{article?.title ?? 'Loading...'}</p>
window
or document
Outside useEffect
Since window
and document
don’t exist on the server, using them outside useEffect
in SSR apps like Next.js causes crashes.
Fix:
useEffect(() => {
console.log(window.innerWidth);
}, []);
React expects the server-rendered HTML to match the client-rendered version. If there's a mismatch, you'll get a crash or hydration warning.
Common Mistake:
<p>{Date.now()}</p> // Different every time
Fix:
Move dynamic logic to useEffect
or only run it on the client.
ssr: false
If you're using libraries like charts, maps, or modals that require window
, importing them server-side can crash your app.
Fix:
import dynamic from 'next/dynamic';
const NoSSRComponent = dynamic(() => import('./MyChart'), { ssr: false });
Sometimes, third-party ad scripts or analytics (like Google AdSense or Facebook Pixel) can break the app if not loaded properly.
Fix:
Wrap third-party scripts safely, and load them after hydration using useEffect
.
page-client.tsx
Ensure your custom hooks or API calls don't throw unhandled errors.
Tip: Use try...catch
in async functions and useEffect
blocks.
1. Check Browser Console
Open Dev Tools → Console tab to view the real stack trace.
2. Use Vercel or Netlify Logs
If deployed on Vercel, go to Vercel Dashboard → Logs to see real-time client-side and server-side errors.
3. Wrap in Error Boundaries
Prevent the app from fully crashing:
class ErrorBoundary extends React.Component {
state = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
render() {
if (this.state.hasError) return <h1>Something went wrong.</h1>;
return this.props.children;
}
}
npm run build
and fix all warningsnpm run start
The error “A client-side exception has occurred” is fixable with the right debugging steps. Most of the time, it comes down to:
Take the time to review your components, add fallbacks, and ensure error boundaries are in place. This will ensure a smoother, crash-free experience for your users.