sentry-javascript
sentry-javascript copied to clipboard
Next.js Turbopack Support
⚠️ 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 |
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
any news on this?
@mdugue We'll tackle turbopack when it becomes somewhat stable.
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
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
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 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.
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 🙏
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.
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
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 .
- This can probably be resolved by using
- Wrapping of various server functionalities
- Error reporting can be replaced by new
onRequestErrorhook - Performance reporting can be outsourced to Next.js OTEL instrumentation
- Error reporting can be replaced by new
sentry.client.config.tsinjection- TBD
- Error reporting of pages router pages render errors
- TBD
- Sourcemap upload
- TBD
- React component annotations
- TBD