Skip to content

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

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.tsimport{withSentryConfig}from'@sentry/nextjs';importtype{NextConfig}from'next';constnextConfig: NextConfig={};exportdefaultwithSentryConfig(nextConfig,{org: 'my-org',project: 'my-project',silent: true,_experimental: {turbopackApplicationKey: 'my-app',},});
// sentry.client.config.tsimport*asSentryfrom'@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.tsimport*asSentryfrom'@sentry/nextjs';import'./sentry.client.config';exportconstonRouterTransitionStart=Sentry.captureRouterTransitionStart;
// app/layout.tsximport{GoogleTagManager}from'@next/third-parties/google';exportdefaultfunctionRootLayout({
children,}: {children: React.ReactNode;}){return(<htmllang="en"><body><GoogleTagManagergtmId="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 JS-1710 / #19542.

I understand there was follow-up discussion in JS-1710 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions