Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js Turbopack Support #8105

Open
Tracked by #85531
ryanolson-aumni opened this issue May 11, 2023 · 42 comments
Open
Tracked by #85531

Next.js Turbopack Support #8105

ryanolson-aumni opened this issue May 11, 2023 · 42 comments
Assignees
Labels
Migrated Package: nextjs Issues related to the Sentry Nextjs SDK Type: Improvement

Comments

@ryanolson-aumni
Copy link

ryanolson-aumni commented May 11, 2023

⚠️ 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 Nov 6, 2024)

Feature Support Notes
Next.js app compiles and runs without issues
Server-side instrumentation
Client-side instrumentation Doable with a little bit of setup - slightly/very hacky - needs documentation
Source Maps - Needs onBuildEnd hook implemented in Next.js
- Needs way to inject debug IDs into bundles implemented in Next.js
React Component Name Annotations - Needs way to transform code in Next.js
Release Injection As a user you probably don't care about this one, but it will become relevant once Turbopack prod builds are a thing. We will likely solve this with v9 of the SDK (coming Jan 2025).
@smeubank
Copy link
Member

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. unjs/unplugin#302

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

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

@mdugue
Copy link

mdugue commented Sep 18, 2023

any news on this?

@lforst
Copy link
Member

lforst commented Sep 21, 2023

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

@smeubank
Copy link
Member

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

unjs/unplugin#302

@lforst
Copy link
Member

lforst commented Oct 18, 2023

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

@Stanzilla
Copy link

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?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Dec 14, 2023
@lforst
Copy link
Member

lforst commented Dec 15, 2023

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

@leerob
Copy link

leerob commented Feb 10, 2024

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 🙏

@r34son
Copy link

r34son commented Jan 15, 2025

Thanks for sharing the link for the fix. As fas as I know, this should also work with an override. In pnpm it's not a key at the root of the package.json. You have to wrap it with the key "pnpm" like this:

 "pnpm": {
    "overrides": {
       "import-in-the-middle": "1.11.2"
    }
  }

And just for context: In npm it's overrides as well, but on the root-level.

Overrides doesn't hoist packages to the root level of node_modules. How can it fix the issue?

@stevejcox
Copy link

Curious if this is on a roadmap, we'd really like to see this implemented.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 24, 2025
@MisterJimson
Copy link

@r34son I found that a .npmrc with the following worked for me for pnpm.

public-hoist-pattern[]=*import-in-the-middle*
public-hoist-pattern[]=*require-in-the-middle*

@r34son
Copy link

r34son commented Jan 24, 2025

@r34son I found that a .npmrc with the following worked for me for pnpm.

public-hoist-pattern[]=*import-in-the-middle*
public-hoist-pattern[]=*require-in-the-middle*

Exactly like i mentioned here vercel/next.js#68805 (comment)

@jlvdh
Copy link

jlvdh commented Feb 21, 2025

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

This unfortunately still gave a lot of errors for us as we imported the sentry package for captureException on other places. We fixed it by mocking Sentry for turbopack builds:

  experimental: {
    turbo: {
      resolveAlias: {
        "@sentry/nextjs": "./src/mocks/sentry-mock.ts",
      },
    },
  },

@calvinf
Copy link

calvinf commented Feb 27, 2025

Per areweturboyet.com, production Next.js support for Turbopack is currently (as of Feb. 27, 2025) at 98.3%.

7760 of 7895 next build tests passing (135 left for 100%)

This will get more urgent when Next fully lights up production support for Turbopack.

@lforst
Copy link
Member

lforst commented Feb 28, 2025

@calvinf, we are in talks with Vercel, and this is being actively worked on. We need Next.js to ship a few features for us to be able to support turbopack. Stay tuned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Migrated Package: nextjs Issues related to the Sentry Nextjs SDK Type: Improvement
Projects
Status: No status
Development

No branches or pull requests