Skip to content

Next.js not capturing client-side errors #10669

Closed
@LauraImpact

Description

@LauraImpact

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.101.0

Framework Version

"next": "^13.5.4",

Link to Sentry event

No response

SDK Setup

sentry.client.config.ts


import * as Sentry from "@sentry/nextjs";

if (process.env.NODE_ENV !== "development") {
  Sentry.init({
    dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
    environment: process.env.VERCEL_ENV,
    // Adjust this value in production, or use tracesSampler for greater control
    tracesSampleRate: 1,

    // Setting this option to true will print useful information to the console while you're setting up Sentry.
    debug: true,

    replaysOnErrorSampleRate: 1.0,

    // This sets the sample rate to be 10%. You may want this to be 100% while
    // in development and sample at a lower rate in production
    replaysSessionSampleRate: 0.1,

    // You can remove this option if you're not planning to use the Sentry Session Replay feature:
    integrations: [
      Sentry.replayIntegration({
        // Additional Replay configuration goes in here, for example:
        maskAllText: true,
        blockAllMedia: true,
      }),
    ],
  });
}

Steps to Reproduce

When a client-side exception occurs and the error.tsx page is rendered, the error is logged to the console but not captured in Sentry. Server-side issues are captured by Sentry without problems.

src/app/error.tsx

"use client";
import React, { useEffect } from "react";
import * as Sentry from "@sentry/nextjs";
import Image from "next/image";
import Logo from "@/components/assets/Logo";
import useTranslation from "next-translate/useTranslation";

const Error = ({ error }: { error: any }) => {
  const { t } = useTranslation("common");

  useEffect(() => {
    console.log("useEffect error: ", error);
    Sentry.captureException(error);
  }, [error]);

  return (
    <main>
      <div className="relative py-16 px-4 md:bg-gradient-to-b from-white from-133 via-[#222433] via-133.5 to-grey-100 to-133.5 md:pt-32 md:pl-[7%] md:min-h-168 lg:pl-76">
        <Image
          src="/img/background-character.svg"
          alt={t("characterAltText")}
          width="487"
          height="372"
          className="hidden absolute md:block md:py-9 md:left-[60%] lg:left-192 z-0"
          priority={true}
        />
        <div className="flex">
          {" "}
          <div className="max-w-[96%] w-96 mx-auto mt-4 pt-11 px-10 pb-16 border rounded-md bg-white shadow-auth relative z-10 md:mx-0">
            <div className="flex justify-center mb-7">
              <Logo width={840} height={130} />
            </div>
            <h1>{t("unknownError")}</h1>
          </div>
        </div>
      </div>
    </main>
  );
};

export default Error;

Expected Result

When error page is rendered, error should be captured as an issue in Sentry

Actual Result

Logs

Sentry Logger [log]: [Tracing] Finishing navigation transaction: /dashboard/system-admin/users.
Sentry Logger [log]: Adding outcome: "network_error:transaction"
Sentry Logger [error]: Error while sending event: TypeError: Failed to fetch
TypeError: Cannot destructure property 'id' of 'n' as it is null.
useEffect error:  TypeError: Cannot destructure property 'id' of 'n' as it is null.
Sentry Logger [info]: [Replay] Converting buffer to session
Sentry Logger [log]: Sending outcomes: 
[
    {
        "reason": "network_error",
        "category": "transaction",
        "quantity": 1
    }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions