DEV Community

Cover image for The Easiest Way to Handle Production Errors in Next.js App Router
Mark Kaave
Mark Kaave

Posted on

The Easiest Way to Handle Production Errors in Next.js App Router

Next.js 14/15 is great, but handling production errors in the App Router can be tricky. You usually have two options:

  1. console.log — which you can’t see in production

  2. Sentry — which requires heavy config, source maps, and a complex dashboard

If you’re a solo developer or indie hacker, you just want to know when it breaks and why.

You don’t need a full observability suite.

🚧 The “Hard” Way (Sentry / Enterprise)

Sentry is powerful, but the setup can be exhausting:

  • Install a heavy SDK

  • Wrap your entire Next.js config with withSentryConfig

  • Upload source maps during every build

  • Dig through a dashboard full of metrics, traces, replays…
    just to find your stack trace

For big teams, that’s fine.
For indie projects? It’s overkill.

✨ The “Indie” Way (BugMail)

For my latest micro-SaaS, I wanted something lighter. Something that just works.

I discovered BugMail. The idea is simple: errors as emails.

When your app crashes, you get an email instantly with the stack trace.

  • No setup hell
  • No learning curve
  • No unnecessary features

🔧 Setup
1. Install the SDK

npm install @bugmail-js/next
Enter fullscreen mode Exit fullscreen mode

2. Create a BugMail project

Go to bugmail.site → create an account → create a project → copy your API key + Project ID.

3. Add a Provider (app/providers.tsx)

'use client';
import { BugMailProvider } from '@bugmail-js/next';

export function Providers({ children }) {
  return (
    <BugMailProvider
      apiKey={process.env.NEXT_PUBLIC_BUGMAIL_API_KEY}
      projectId={process.env.NEXT_PUBLIC_BUGMAIL_PROJECT_ID}
      endpoint="https://api.bugmail.site"
    >
      {children}
    </BugMailProvider>
  );
}
Enter fullscreen mode Exit fullscreen mode

4. Add an Error Handler (app/error.tsx)

'use client';
import { useEffect } from 'react';
import { createAppRouterErrorHandler } from '@bugmail-js/next';

const reportError = createAppRouterErrorHandler({
  apiKey: process.env.NEXT_PUBLIC_BUGMAIL_API_KEY,
  projectId: process.env.NEXT_PUBLIC_BUGMAIL_PROJECT_ID,
  baseUrl: 'https://api.bugmail.site',
  environment: process.env.NODE_ENV,
});

export default function Error({ error, reset }) {
  useEffect(() => {
    reportError(error);
  }, [error]);

  return <button onClick={() => reset()}>Try again</button>;
}
Enter fullscreen mode Exit fullscreen mode

5. Add your env variables

NEXT_PUBLIC_BUGMAIL_API_KEY=your_api_key
NEXT_PUBLIC_BUGMAIL_PROJECT_ID=your_project_id
Enter fullscreen mode Exit fullscreen mode

That’s it.

✅ Result

Now, whenever a user crashes your app:

  • You instantly get an email with the full stack trace
  • You fix it
  • You archive the bug
  • No dashboard fatigue.
  • No complex config.
  • Just visibility when it matters.

🎯 Conclusion

You don’t need enterprise-grade observability tools for indie projects.

If all you want is to know when your app breaks —
keep your stack lean.

BugMail is free to start.
Try it on your next side project.

Bugmail

Top comments (0)