sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Next.js Turbopack Support

Open ryanolson-aumni opened this issue 2 years ago • 73 comments

⚠️ This original post has been edited by @lforst to reflect the current status of Turbopack Support ⚠️ [!IMPORTANT] This issue is tracking progress on Turbopack Support. If you find bugs or problems with the Sentry SDK in combination with Turbopack please open a separate issue. Thank you!

Problem Statement

Sentry should work in combination with Turbopack with all of its features.

Current Status (Last Update May 5, 2025)

Feature Support Notes
Next.js app compiles and runs without issues
Server-side instrumentation
Client-side instrumentation - Upgrade to SDK version 9.9.0 or greater
- Upgrade to Next.js canary 15.3.0-canary.8 or greater
- Add instrumentation-client.ts file with Sentry.init() call. (sentry.client.config.ts can be replaced with instrumentation-client.ts. It serves the same purpose.)
Release Injection - Upgrade SDK to version 9.11.0
Source Maps - Needs runAfterProductionCompile hook implemented in Next.js (done in Next.js 15.4.0-canary.19)
- Needs way to inject debug IDs into bundles implemented in Next.js
React Component Name Annotations - Needs way to transform code in Next.js
- Will likely not be possible for the forseeable future

ryanolson-aumni avatar May 11 '23 21:05 ryanolson-aumni

Hi @ryanolson-aumni

We are also eager to add support here!

We have 2 plugin repos to add support for webpack, esbuild, rollup, and vite. The latter 3 we support via an opensource project where we'd love to see support so we could potentially adopt it via our usage of their adapters. Upvote the issue there as well. Although I do not think it is on their immediate radar either. https://github.com/unjs/unplugin/issues/302

https://github.com/getsentry/sentry-webpack-plugin

https://github.com/getsentry/sentry-javascript-bundler-plugins

smeubank avatar May 12 '23 11:05 smeubank

any news on this?

mdugue avatar Sep 18 '23 12:09 mdugue

@mdugue We'll tackle turbopack when it becomes somewhat stable.

lforst avatar Sep 21 '23 11:09 lforst

any news on this?

Fwiw I would also encourage you to upvote and comment on this issue which wr could also use to provide support similar to webpack, vite, esbuild and rollup

https://github.com/unjs/unplugin/issues/302

smeubank avatar Sep 21 '23 12:09 smeubank

Update

As of now, we cannot transfer the functionality we currently have in the SDK to Turbopack:

Turbopack loaders are not passed transpiled javascript, instead, they are passed the original user code. The SDK needs transpiled JS to properly be able to do transformations to modules. We could transpile the user code ourselves but that is fragile AF - so not an option.

As of now, the SDK will continue to work in production mode which is arguably more important, but we would like to support dev mode.

Branch with my experiments: #9295

lforst avatar Oct 18 '23 10:10 lforst

Update

As of now, we cannot transfer the functionality we currently have in the SDK to Turbopack:

Turbopack loaders are not passed transpiled javascript, instead, they are passed the original user code. The SDK needs transpiled JS to properly be able to do transformations to modules. We could transpile the user code ourselves but that is fragile AF - so not an option.

As of now, the SDK will continue to work in production mode which is arguably more important, but we would like to support dev mode.

Branch with my experiments: #9295

To clarify, does it work with Turbopack in production mode as-is or only with the changes in your branch?

Stanzilla avatar Dec 14 '23 23:12 Stanzilla

@Stanzilla Turbopack will not work with the SDK (dev and prod). My branch does not contain any fixes or features, just experiments proving that things don't work.

lforst avatar Dec 15 '23 11:12 lforst

It's also worth noting that the initial Turbopack support is for next dev, which is only for your local environment. next build support will come later 🙏

leerob avatar Feb 10 '24 15:02 leerob

I would love to get rid of the Sentry SDK's dependency on build tooling (i.e. Webpack and Turbopack) entirely. The reason we need to rely on Webpack at the moment is that Next.js lacks options to instrument Next.js apps. Webpack was the next entry point higher up in the chain of abstraction that allowed the SDK to do the stuff it needed to do.

Newer versions of Next.js already have the instrumentation.ts hook and OTEL support. This is very good. The only thing we lack now is a central hook that reports all errors inside a Next.js application (with metadata (!), eg. what route the error was thrown in).

We will do our best to support Turbopack when it becomes relevant. However, upstream changes are needed. I do not believe Sentry is the only player that would profit from this.

lforst avatar Feb 12 '24 09:02 lforst

For people looking to use turbo locally you can only use withSentryConfig when building.

/** @type {import('next').NextConfig} */
let nextConfig = {}

if (process.env.NODE_ENV === 'production') {
    const { withSentryConfig } = await import('@sentry/nextjs')
    nextConfig = withSentryConfig(nextConfig, {})
}

export default nextConfig

fromthemills avatar Aug 08 '24 13:08 fromthemills

I think we are slowly moving into a world where we can think about getting rid of all of our reliance on webpack. These are the following features we use it for:

  • Various variable injection
    • This can probably be resolved by using process.env.NEXT_PUBLIC_ constants .
  • Wrapping of various server functionalities
    • Error reporting can be replaced by new onRequestError hook
    • Performance reporting can be outsourced to Next.js OTEL instrumentation
  • sentry.client.config.ts injection
    • TBD
  • Error reporting of pages router pages render errors
    • TBD
  • Sourcemap upload
    • TBD
  • React component annotations
    • TBD

lforst avatar Aug 13 '24 08:08 lforst