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

react-error-logger

v0.1.1

Published

React component for catching and logging JavaScript errors, unhandled promise rejections, and React ErrorBoundary errors with the ability to view and download logs

Readme

react-error-logger

npm version License: MIT

A comprehensive React component for catching, logging, and managing JavaScript errors, unhandled promise rejections, and React ErrorBoundary errors in your React applications. Perfect for debugging and error tracking during development and production.

Features

  • 🎯 Comprehensive Error Catching: Automatically captures JavaScript errors, unhandled promise rejections, and React ErrorBoundary errors
  • 💾 Persistent Storage: Errors are saved to localStorage and persist across page reloads
  • 🎨 User-Friendly UI: Clean, modern interface with a floating button and modal for viewing errors
  • 📥 Export Functionality: Download error logs as a text file for further analysis
  • 🔍 Detailed Information: Captures stack traces, component stacks, source locations, and timestamps
  • Zero Configuration: Works out of the box with minimal setup
  • 📦 TypeScript Support: Fully typed with TypeScript definitions included
  • 🎛️ Customizable: Easy to integrate with existing ErrorBoundary components

Installation

npm install react-error-logger

or

yarn add react-error-logger

or

pnpm add react-error-logger

Peer Dependencies

This library requires React 18.2.0 or higher:

npm install react@^18.2.0 react-dom@^18.2.0

Quick Start

Basic Usage

Simply add the ReactErrorLogger component to your app:

import { ReactErrorLogger } from 'react-error-logger';

function App() {
  return (
    <div>
      {/* Your app content */}
      <ReactErrorLogger />
    </div>
  );
}

With ErrorBoundary

For React ErrorBoundary errors, use the handleReactErrorLogger function with your ErrorBoundary:

import { ErrorBoundary } from 'react-error-boundary';
import { ReactErrorLogger, handleReactErrorLogger } from 'react-error-logger';

function App() {
  return (
    <ErrorBoundary onError={handleReactErrorLogger} fallback={<div>Something went wrong</div>}>
      {/* Your app content */}
      <ReactErrorLogger />
    </ErrorBoundary>
  );
}

API Reference

ReactErrorLogger

The main component that provides the UI for viewing and managing error logs.

Props: None (component is self-contained)

Features:

  • Floating button with error count badge
  • Modal window for viewing all errors
  • Download logs as text file
  • Clear all logs functionality

handleReactErrorLogger

A callback function for React ErrorBoundary components to log errors.

Signature:

handleReactErrorLogger(error: Error, errorInfo: ErrorInfo): void

Usage:

<ErrorBoundary onError={handleReactErrorLogger}>
  {/* Your components */}
</ErrorBoundary>

ErrorLogger

A singleton class for programmatic error logging (optional advanced usage).

Methods:

  • getInstance(): Get the ErrorLogger instance
  • saveLog(log: ErrorLog): Save an error log
  • loadLogs(): Load all saved error logs
  • clearLogs(): Clear all saved error logs
  • createErrorLogFromEvent(event: ErrorEvent): Create log from ErrorEvent
  • createErrorLogFromRejection(event: PromiseRejectionEvent): Create log from PromiseRejectionEvent
  • createErrorLogFromBoundary(error: Error, errorInfo: ErrorInfo): Create log from ErrorBoundary

Error Types

The library captures three types of errors:

  1. JavaScript Errors (error): Standard JavaScript errors caught by window.onerror
  2. Unhandled Promise Rejections (unhandledrejection): Promise rejections that aren't handled
  3. React ErrorBoundary Errors (errorboundary): Errors caught by React ErrorBoundary components

Error Log Structure

Each error log contains the following information:

interface ErrorLog {
  timestamp: string;        // ISO timestamp
  message: string;          // Error message
  type: 'error' | 'unhandledrejection' | 'errorboundary';
  source?: string;          // Source file URL
  lineno?: number;          // Line number
  colno?: number;           // Column number
  error?: string;           // Error string representation
  stack?: string;           // Stack trace
  componentStack?: string;  // React component stack (for ErrorBoundary)
}

Styling

The component includes default styles that are automatically imported. The styles are scoped and won't interfere with your application's styles.

If you need to customize the appearance, you can override the CSS classes:

  • .floatingButton - The floating action button
  • .modalOverlay - The modal backdrop
  • .modalContent - The modal container
  • .logItem - Individual error log item
  • And more...

Browser Support

This library works in all modern browsers that support:

  • ES6+ features
  • localStorage API
  • React 18+

Storage

Errors are stored in the browser's localStorage under the key debug_error_logs. The storage is persistent across page reloads and browser sessions.

Note: Be aware of localStorage size limits (typically 5-10MB depending on the browser). The library doesn't implement automatic log rotation, so you may want to periodically clear logs in production.

Development

# Install dependencies
pnpm install

# Run development server
pnpm dev

# Build library
pnpm build

# Lint code
pnpm lint

# Fix linting issues
pnpm lint:fix

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with ❤️ for the React community