npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ez-fe-error-handler

v1.0.3

Published

Global & Component error reporting for React & Next.js with email alerts

Readme

ez-fe-error-handler

Automated error monitoring with instant email alerts for React & Next.js applications

Never miss critical production errors again. ez-fe-error-handler automatically captures and reports React errors, unhandled promise rejections, and global JavaScript errors directly to your email inbox with detailed device information and stack traces.

Features

  • 🚨 Automatic Error Detection - Catches React component errors, promise rejections, and global errors
  • 📧 Instant Email Alerts - Get notified immediately when errors occur in production
  • 🔍 Rich Error Context - Includes stack traces, page URL, browser, OS, IP address, and timestamp
  • Zero Config Setup - Simple integration with just a few lines of code
  • 🎯 Framework Support - Works seamlessly with both React and Next.js (App Router & Pages Router)
  • 🛡️ Type-Safe - Written in TypeScript with full type definitions

Installation

npm install ez-fe-error-handler

Peer Dependencies

npm install react react-dom react-error-boundary

Quick Start

Next.js (App Router)

1. Create an Error Provider Component

// app/ErrorProviders.tsx
"use client";

import {
  ClientErrorInit,
  ClientErrorBoundary,
  configureErrorReceiverEmails,
  configureApiUrl,
} from "ez-fe-error-handler";

// Configure email recipients
const emails = process.env.NEXT_PUBLIC_ERROR_RECEIVER_EMAILS?.split(",") || [];
configureErrorReceiverEmails({ emails });
configureApiUrl(process.env.NEXT_PUBLIC_API_URL);

export default function ErrorProviders({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <>
      <ClientErrorInit />
      <ClientErrorBoundary>{children}</ClientErrorBoundary>
    </>
  );
}

2. Wrap Your App in the Root Layout

// app/layout.tsx
import ErrorProviders from "./ErrorProviders";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <ErrorProviders>{children}</ErrorProviders>
      </body>
    </html>
  );
}

React (Vite/CRA)

// main.tsx or index.tsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

import {
  ClientErrorBoundary,
  ClientErrorInit,
  configureErrorReceiverEmails,
  configureApiUrl,
} from "ez-fe-error-handler";

// Configure email recipients

const emails =
  import.meta.env.VITE_ERROR_RECEIVER_EMAILS?.split(",").map((email: string) =>
    email.trim()
  ) || [];
const apiUrl = import.meta.env.VITE_APP_EMAIL_API_URL;

configureErrorReceiverEmails({ emails });
configureApiUrl(apiUrl);

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <ClientErrorBoundary>
      <ClientErrorInit />
      <App />
    </ClientErrorBoundary>
  </StrictMode>
);

Configuration

API Endpoint

Set your email service API endpoint:

configureApiUrl("https://your-backend.com/api/v1/send-email");

The API endpoint should accept POST requests with the following structure:

{
  "recipients": ["[email protected]", "[email protected]"],
  "subject": "Production Error Alert",
  "email_content": "<html>...</html>"
}

Email Format

Error emails include comprehensive debugging information:

  • Error Message - The actual error that occurred
  • Page URL - Where the error happened
  • Browser - Chrome, Firefox, Safari, Edge, etc.
  • Operating System - Windows, macOS, Linux, iOS, Android
  • IP Address - User's IP for additional context
  • Timestamp - When the error occurred (IST timezone)
  • Stack Trace - Full error stack for debugging

API Components

configureErrorReceiverEmails(config)

Set up email recipients for error notifications.

Parameters:

  • config.emails (string[]): Array of email addresses

configureApiUrl(url)

Configure the email service endpoint.

Parameters:

  • url (string): Your email API endpoint URL

<ClientErrorBoundary>

React Error Boundary component that catches component errors.

Props:

  • children (ReactNode): Your app components

<ClientErrorInit>

Initializes global error handlers for promise rejections and window errors.

Usage: Place at the top level of your app (no props needed)

Error Types Captured

  1. React Component Errors - Errors during rendering, lifecycle methods, or constructors
  2. Unhandled Promise Rejections - Async errors that weren't caught
  3. Global JavaScript Errors - Runtime errors anywhere in your application

Environment Considerations

The package is designed for client-side only and includes SSR checks. It won't execute on the server in Next.js applications.

Production vs Development

While the package works in all environments, you may want to conditionally enable it:

const isProduction = process.env.NODE_ENV === "production";

if (isProduction) {
  configureErrorReceiverEmails({
    emails: ["[email protected]"],
  });
  configureApiUrl("https://api.company.com/send-email");
}

Best Practices

  1. Use Environment Variables - Store email API URLs in environment variables
  2. Separate Alert Channels - Use different emails for staging vs production
  3. Rate Limiting - Implement rate limiting on your email API to prevent spam
  4. Error Deduplication - Consider implementing error grouping on your backend
  5. Privacy Compliance - Ensure IP collection complies with your privacy policy

Backend API Example

Your email endpoint should handle requests like:

// Example Express.js endpoint
app.post("/api/v1/send-email", async (req, res) => {
  const { recipients, subject, email_content } = req.body;

  // Send email using your preferred service (SendGrid, AWS SES, etc.)
  await sendEmail({
    to: recipients,
    subject: subject,
    html: email_content,
  });

  res.status(200).json({ success: true });
});

Troubleshooting

Emails Not Being Sent

  1. Verify configureApiUrl() is called before errors occur
  2. Check that configureErrorReceiverEmails() has valid email addresses
  3. Ensure your API endpoint is accessible from the client
  4. Check browser console for any fetch errors

Errors Not Being Caught

  1. Ensure <ClientErrorBoundary> wraps your entire app
  2. Verify <ClientErrorInit /> is rendered at the top level
  3. Check that the package is installed correctly with peer dependencies

License

MIT