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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codybontecou/pr-error-logger

v1.0.2

Published

A comprehensive TypeScript package for logging errors to GitHub PRs with Vercel integration

Readme

PR Error Logger

A comprehensive TypeScript package for automatically logging browser errors, warnings, and console output to GitHub Pull Request comments. Perfect for debugging issues in Vercel preview deployments.

Features

  • 🔍 Automatic Error Capture - Catches all browser errors and unhandled promise rejections
  • 📱 Device Information - Includes viewport, screen size, platform, and browser details
  • 🚀 Vercel Integration - Automatically detects PR numbers from Vercel preview URLs
  • 📝 GitHub PR Comments - Posts detailed error reports directly to the relevant PR
  • TypeScript First - Full TypeScript support with comprehensive type definitions
  • 🧩 Modular Design - Separate client/server modules for flexible usage
  • 🎯 Framework Agnostic - Works with Next.js App Router and Pages Router
  • 🤖 GitHub Action - Automated setup for new projects

Installation

Option 1: GitHub Action (Recommended)

Add this to your .github/workflows/setup-error-logging.yml:

```yaml name: Setup PR Error Logger on: push: branches: [main]

jobs: setup: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: your-org/pr-error-logger@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} ```

Option 2: Manual Installation

```bash npm install @your-org/pr-error-logger ```

Quick Start

1. Set up the API endpoint

Create pages/api/log-error.ts (or app/api/log-error/route.ts for App Router):

```typescript import { createApiHandler } from '@your-org/pr-error-logger/server';

export default createApiHandler(); ```

2. Initialize the client

In your pages/_app.tsx:

```typescript import { PRErrorLogger } from '@your-org/pr-error-logger/client';

// Initialize error logging if (typeof window !== 'undefined') { new PRErrorLogger({ enableConsoleCapture: true, enableErrorCapture: true, enableWarningCapture: true, }); }

export default function App({ Component, pageProps }) { return <Component {...pageProps} />; } ```

3. Configure environment variables

Add to your .env.local:

``` GITHUB_TOKEN=your_github_token_here VERCEL_GIT_REPO_OWNER=your-username VERCEL_GIT_REPO_SLUG=your-repo-name ```

Usage Examples

Basic Error Logging

```typescript import { PRErrorLogger } from '@your-org/pr-error-logger/client';

const logger = new PRErrorLogger();

// Manual logging logger.manualLog('Custom error message', 'error', { userId: 123 });

// Automatic error capture is enabled by default throw new Error('This will be automatically logged'); ```

Advanced Configuration

```typescript import { PRErrorLogger } from '@your-org/pr-error-logger/client';

const logger = new PRErrorLogger({ apiEndpoint: '/api/custom-error-handler', enableConsoleCapture: true, enableErrorCapture: true, enableWarningCapture: false, maxLogEntries: 50, debounceMs: 2000, }); ```

Server-side Usage

```typescript import { GitHubService } from '@your-org/pr-error-logger/server';

const github = new GitHubService( process.env.GITHUB_TOKEN!, 'owner', 'repository' );

await github.postErrorComment(123, errorLogs); ```

API Reference

PRErrorLogger

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiEndpoint | string | /api/log-error | Endpoint for sending logs | | enableConsoleCapture | boolean | true | Capture console.log/warn/error | | enableErrorCapture | boolean | true | Capture window errors | | enableWarningCapture | boolean | true | Capture console warnings | | maxLogEntries | number | 100 | Maximum logs to buffer | | debounceMs | number | 1000 | Debounce time for sending logs |

Methods

  • manualLog(message, level, data?) - Manually log a message
  • flush() - Force send all buffered logs
  • destroy() - Clean up event listeners

How It Works

  1. Error Capture: The client automatically captures browser errors, console logs, and device information
  2. PR Detection: Uses Vercel environment variables to identify the PR number
  3. Batching: Logs are batched and sent to your API endpoint with debouncing
  4. GitHub Integration: Server processes logs and posts formatted comments to the relevant PR
  5. Update Logic: Existing error comments are updated rather than creating new ones

Environment Variables

| Variable | Description | Required | |----------|-------------|----------| | GITHUB_TOKEN | GitHub token with repo access | Yes | | VERCEL_GIT_REPO_OWNER | Repository owner | Auto-detected | | VERCEL_GIT_REPO_SLUG | Repository name | Auto-detected | | VERCEL_URL | Deployment URL | Auto-detected | | VERCEL_ENV | Environment (preview/production) | Auto-detected |

TypeScript Support

Full TypeScript definitions are included:

```typescript import type { ErrorLogEntry, DeviceInfo, LoggerConfig } from '@your-org/pr-error-logger'; ```

Contributing

  1. Clone the repository
  2. Install dependencies: npm install
  3. Build the package: npm run build
  4. Run tests: npm test

Publishing

  1. Update version in package.json
  2. Build: npm run build
  3. Publish: npm publish
  4. Create GitHub release with tag for Action usage

License

MIT License - see LICENSE file for details.