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

@interfere/next

v0.0.14

Published

Build apps that never break.

Downloads

47

Readme

@interfere/next

Official Next.js SDK for Interfere error monitoring and analytics.

Installation

npm install @interfere/next
# or
yarn add @interfere/next
# or
pnpm add @interfere/next

Quick Start

1. Initialize the SDK

Create a file to initialize Interfere (e.g., lib/interfere.ts):

import { init } from '@interfere/next';

export const interfere = init({
  project: process.env.NEXT_PUBLIC_INTERFERE_PROJECT_ID!,
  options: {
    env: process.env.NODE_ENV as 'development' | 'preview' | 'production',
    debug: process.env.NODE_ENV === 'development',
  },
});

2. Add Error Boundary (App Directory)

In your root layout (app/layout.tsx):

import { InterfereProvider, InterfereErrorBoundary } from '@interfere/next';
import { interfere } from '@/lib/interfere';

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

3. Add Error Handler (App Directory)

Create app/error.tsx:

'use client';

import { useEffect } from 'react';
import { captureErrorBoundaryError } from '@interfere/next';

export default function Error({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    captureErrorBoundaryError(error, {
      componentStack: error.stack || '',
    });
  }, [error]);

  return (
    <div>
      <h2>Something went wrong!</h2>
      <button onClick={() => reset()}>Try again</button>
    </div>
  );
}

4. Add Global Error Handler

Create app/global-error.tsx:

'use client';

import { createInterfereErrorHandler } from '@interfere/next';

const errorHandler = createInterfereErrorHandler();

export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  errorHandler(error, { digest: error.digest });

  return (
    <html>
      <body>
        <h2>Something went wrong!</h2>
        <button onClick={() => reset()}>Try again</button>
      </body>
    </html>
  );
}

API Routes

Automatic Error Capture

Wrap your API route handlers:

// app/api/users/route.ts
import { withInterfereApiRoute } from '@interfere/next';

export const GET = withInterfereApiRoute(async (request) => {
  // Your API logic here
  const users = await fetchUsers();
  return Response.json(users);
});

Manual Error Capture

// app/api/webhook/route.ts
import { captureServerError } from '@interfere/next';

export async function POST(request: Request) {
  try {
    const body = await request.json();
    // Process webhook
  } catch (error) {
    captureServerError(error, request, {
      pathname: '/api/webhook',
      type: 'webhook_error',
    });
    return Response.json({ error: 'Webhook failed' }, { status: 500 });
  }
}

Middleware

Wrap your middleware to capture errors:

// middleware.ts
import { withInterfereMiddleware } from '@interfere/next';
import { NextResponse } from 'next/server';

export default withInterfereMiddleware(async (request) => {
  // Your middleware logic
  return NextResponse.next();
});

export const config = {
  matcher: '/api/:path*',
};

Server Components

Wrap async server components:

// app/dashboard/page.tsx
import { withInterfereServerComponent } from '@interfere/next';

async function DashboardPage() {
  const data = await fetchDashboardData();
  return <Dashboard data={data} />;
}

export default withInterfereServerComponent(DashboardPage, 'DashboardPage');

Custom Event Capture

Capture custom events and errors:

import { capture, captureServerError } from '@interfere/next';

// Capture custom events
capture('custom', {
  action: 'user_signup',
  userId: user.id,
  plan: 'premium',
});

// Capture handled errors
try {
  await riskyOperation();
} catch (error) {
  captureServerError(error, undefined, {
    operation: 'risky_operation',
    context: { userId: user.id },
  });
}

React Hook

Use the useInterfere hook in client components:

'use client';

import { useInterfere } from '@interfere/next';

export function Button() {
  const { capture } = useInterfere();

  const handleClick = () => {
    capture('ui_event', {
      action: 'button_click',
      label: 'cta_button',
    });
  };

  return <button onClick={handleClick}>Click me</button>;
}

Configuration Options

init({
  project: 'if_proj_xxx', // Your project ID
  options: {
    env: 'production', // 'development' | 'preview' | 'production'
    flushInterval: 5000, // Flush interval in ms (client-side only)
    debug: false, // Enable debug logging
    sessionId: 'custom-session-id', // Optional custom session ID
  },
});

Event Types

The SDK automatically captures these event types:

  • error - Client-side errors (unhandled errors, promise rejections)
  • server_error - Server-side errors in API routes and server components
  • edge_error - Edge runtime errors in middleware
  • server_req - Server request events (API routes)
  • edge_req - Edge request events (middleware)
  • ui_event - User interface events
  • custom - Custom application events
  • network - Network request events (coming soon)
  • rage_click - rage clicks

Best Practices

  1. Initialize Early: Initialize Interfere as early as possible in your application lifecycle.

  2. Use Error Boundaries: Always wrap your app with InterfereErrorBoundary to catch React errors.

  3. Wrap Async Functions: Use withErrorCapture or specific wrappers for automatic error tracking.

  4. Add Context: Include relevant context when capturing errors manually:

    captureServerError(error, request, {
      userId: session.userId,
      action: 'update_profile',
      metadata: { ... },
    });
  5. Environment Variables: Store your project ID in environment variables:

    NEXT_PUBLIC_INTERFERE_PROJECT_ID=if_proj_xxx

TypeScript

The SDK is fully typed. Import types as needed:

import type {
  Config,
  InitConfig,
  EventType,
  Envelope,
} from '@interfere/next';

License

MIT