Skip to content

_experimental.turbopackApplicationKey breaks React useEffect during SSR prerendering (Next.js 16 + Turbopack) #20101

@igz0

Description

@igz0

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.47.0

Framework Version

Next.js 16.2.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

Minimal reproduction:
https://github.com/igz0/sentry-nextjs-turbopack-gtm-repro

// next.config.ts
import { withSentryConfig } from '@sentry/nextjs';
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {};

export default withSentryConfig(nextConfig, {
  org: 'my-org',
  project: 'my-project',
  silent: true,
  _experimental: {
    turbopackApplicationKey: 'my-app',
  },
});
// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [
    Sentry.thirdPartyErrorFilterIntegration({
      filterKeys: ['my-app'],
      behaviour: 'drop-error-if-contains-third-party-frames',
    }),
  ],
});
// instrumentation-client.ts
import * as Sentry from '@sentry/nextjs';
import './sentry.client.config';

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
// app/layout.tsx
import { GoogleTagManager } from '@next/third-parties/google';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <GoogleTagManager gtmId="GTM-XXXXXX" />
        {children}
      </body>
    </html>
  );
}

Steps to Reproduce

  1. Create a Next.js 16 app with Turbopack
  2. Install @sentry/nextjs@10.47.0 and @next/third-parties@16.2.2
  3. Enable _experimental.turbopackApplicationKey in withSentryConfig
  4. Configure thirdPartyErrorFilterIntegration
  5. Render GoogleTagManager from @next/third-parties/google in app/layout.tsx
  6. Run npm run build

Expected Result

Build completes successfully.

thirdPartyErrorFilterIntegration should work with Turbopack without breaking SSR prerendering.

Actual Result

Build fails during prerendering of /_not-found with:

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: (0 , g.useEffect) is not a function
    at c.GoogleTagManager (.next/server/chunks/ssr/_0u36dvt._.js:2:9947)
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null

If I remove only this block from next.config.ts, the build succeeds again:

_experimental: {
  turbopackApplicationKey: 'my-app',
},

Additional Context

This seems related to the Turbopack support added for thirdPartyErrorFilterIntegration in #19320 / #19542.

I understand there was follow-up discussion in #19320 about aligning behavior with webpack by treating node_modules as first-party. However, with the current distributed implementation in @sentry/nextjs@10.47.0, enabling _experimental.turbopackApplicationKey appears to break SSR prerendering when GoogleTagManager from @next/third-parties/google is present.

In other words:

  • _experimental.turbopackApplicationKey enabled: build fails
  • _experimental.turbopackApplicationKey removed: build succeeds

Environment:

  • @sentry/nextjs: 10.47.0
  • next: 16.2.2
  • react: 19.2.4
  • @next/third-parties: 16.2.2

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions