Skip to content

Next.js 16 Turbopack duplicates @opentelemetry/api across chunks, causing infinite .with() recursion and fatal RangeError: Maximum call stack size exceeded #19367

@InterstellarStella

Description

@InterstellarStella

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

10.38.0 (works correctly on 10.8.0)

Framework Version

Next.js 16.1.6 (Turbopack, production build), Node.js v24.12.0, Prisma 7.x (@prisma/instrumentation ^7.4.0), pnpm workspaces, deployed on AWS ECS Fargate (Debian 12.13)

Link to Sentry event

No response

Reproduction Example/SDK Setup

// sentry.server.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment,
  tracesSampleRate: 1, // also reproduces with 0
  integrations: [
    Sentry.prismaIntegration(),
  ],
});

@opentelemetry/api resolves to a single version (1.9.0) across the dependency tree:

dependencies:
@sentry/nextjs 10.38.0
├── @opentelemetry/api 1.9.0
└─┬ @sentry/node 10.38.0
   ├── @opentelemetry/api 1.9.0
   ├─┬ @opentelemetry/context-async-hooks 2.5.0
   │  └── @opentelemetry/api 1.9.0 peer
   ├─┬ @opentelemetry/core 2.5.0
   │  └── @opentelemetry/api 1.9.0 peer
   └─┬ @opentelemetry/instrumentation 0.211.0
      └── @opentelemetry/api 1.9.0 peer

Steps to Reproduce

  1. Create a Next.js 16 app using Turbopack (the default) with @sentry/nextjs 10.38.0
  2. Deploy to a Node.js 24 environment (we use AWS ECS Fargate)
  3. The server crashes with RangeError: Maximum call stack size exceeded sometimes within minutes, sometimes after several hours
  4. Setting tracesSampleRate: 0 does not prevent the crash
  5. Setting skipOpenTelemetrySetup: true does not prevent the crash (and introduces MaxListenersExceededWarning from all auto-loaded instrumentations stacking listeners on every request)
  6. Downgrading to @sentry/nextjs 10.8.0 with the same Next.js 16.1.6 and Turbopack resolves the issue completely

Expected Result

The application runs stably without stack overflow errors, as it does on SDK version 10.8.0.

Actual Result

The server fatally crashes with an unhandled RangeError: Maximum call stack size exceeded. The stack trace shows two separate bundled copies of @opentelemetry/api in different Turbopack chunks, whose .with() methods recursively call each other.

Additionally, with skipOpenTelemetrySetup: true, the server experiences rapid MaxListenersExceededWarning floods:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 close listeners added to [ServerResponse]. MaxListeners is 10.

Additional Context

Errors in Sentry are provided in the internal Linear ticket.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions