Skip to content

Next.js: warn at build time when Sentry.init is missing from the client bundle #26956

Backlog

Description

@itsUndefined

Problem Statement

On Next.js 16.4 with Turbopack, the browser SDK can be removed from the build without any warning. Our production app ran for four weeks with no browser errors, traces or replays before we noticed.

The trigger is a sideEffects field in the app's package.json. Ours was ["**/*.css"], added to enable tree-shaking. instrumentation-client.ts follows the documented setup: it calls Sentry.init({...}) and re-exports captureRouterTransitionStart as onRouterTransitionStart. Since Next.js 16.4 (vercel/next.js#97770), Turbopack drops the module's body, init() included, whenever the package declares the file side-effect free; in our bundle only the re-export was left. In the browser @sentry/nextjs still loads, but no client is ever created.

Nothing reports it:

Next.js issue with a minimal reproduction (no Sentry code): vercel/next.js#102502
Reproduction repo: https://github.com/itsUndefined/next-instrumentation-client-sideeffects-repro

Solution Brainstorm

  • Build-time check (main proposal). Under Turbopack, withSentryConfig's value-injection loader already writes values such as _sentryNextJsVersion and _sentryRouteManifest into instrumentation-client. They sit in the same module body as init(), so they disappear with it: the client chunks of our broken production build contained none of them, while in the fixed build they appear in the chunks that contain init. After the production compile, the plugin could check that at least one client chunk still contains an injected marker, and warn (or fail) if none does. That catches any cause of the body being dropped, not only sideEffects, and needs no knowledge of which chunk is the entry.
  • Runtime: in debug builds, log a warning the first time captureRouterTransitionStart runs while no client exists.
  • Docs: extend the troubleshooting entry to cover sideEffects arrays and Next.js 16.4+ Turbopack, with the fix (add ./instrumentation-client.ts to sideEffects, or remove the field).

Happy to send a PR for the build-time check if this direction works for you.

Additional Context

Seen with @sentry/nextjs 10.78 on Next.js 16.4.3 to 16.4.6 (Pages Router, Turbopack, deployed on Vercel). Next.js 16.3.5 and webpack builds keep the init. As far as we can tell from the 11.x changelog and migration guide, v11 doesn't detect this either.

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.

Activity

  1. linear-code commented on Nov 27, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 27, 2026
  3. logaretm commented on Nov 27, 2026

    @logaretm
    Member

    Thanks for the detailed report, this seems like a turbopack regression. At first glance it doesn't seem like we should add a warning to the SDK because this is not an expected outcome from a bundler IMO.

    Since there is a workaround then I would recommend using it in the meanwhile.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 27, 2026
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