nextjs - 💡(How to fix) Fix `instanceof` check fails for custom error classes in Server Side due to suspected module duplication [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87614Fetched 2026-04-08 02:06:49
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
2
Participants
Timeline (top)
issue_type_added ×1labeled ×1subscribed ×1

Error Message

Error Handling

Code Example

Next.js: 14.2.4
React: 18.3.1
@sentry/nextjs: 8.x
Node: 20.15.0
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/developer-choi/reproduce-sentry-instanceof-2025-11-21

To Reproduce

Reproduction steps is here

Current vs. Expected behavior

Expected Result

=== Step 1: Server Component catch block === instanceof CustomApiError: true ✅

=== Step 2: beforeSend === instanceof CustomApiError: true ✅

Actual Result

=== Step 1: Server Component catch block === instanceof CustomApiError: true ✅

=== Step 2: beforeSend === instanceof CustomApiError: false ❌

Provide environment information

Next.js: 14.2.4
React: 18.3.1
@sentry/nextjs: 8.x
Node: 20.15.0

Which area(s) are affected? (Select all that apply)

Error Handling

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

https://github.com/developer-choi/reproduce-sentry-instanceof-2025-11-21/blob/master/README.md

extent analysis

TL;DR

The issue may be resolved by checking the serialization or deserialization of the CustomApiError object, as it loses its instanceof check in the beforeSend step.

Guidance

  • Review the beforeSend function in the Sentry configuration to ensure it does not modify the error object in a way that would cause it to lose its instanceof CustomApiError check.
  • Verify that the CustomApiError class is properly defined and exported, and that it is being correctly instantiated and thrown in the server component.
  • Check the documentation for @sentry/nextjs version 8.x to see if there are any known issues or configuration options related to error serialization or deserialization.
  • Test the beforeSend function with a minimal example to isolate the issue and determine if it is specific to the CustomApiError class or a more general problem with error handling.

Example

No code example is provided as the issue is more related to configuration and error handling rather than a specific code snippet.

Notes

The issue may be specific to the @sentry/nextjs version 8.x or the Next.js version 14.2.4, and upgrading or downgrading these dependencies may resolve the issue. However, without further information, it is difficult to determine the root cause.

Recommendation

Apply a workaround by modifying the beforeSend function to properly handle the CustomApiError object, such as by using a custom serializer or deserializer. This will allow for more control over how the error object is processed and may resolve the instanceof check issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING