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
ryanolson-aumni opened this issue May 11, 2023 · 19 comments
Open

Next.js Turbopack Support #8105

ryanolson-aumni opened this issue May 11, 2023 · 19 comments
Assignees
Labels
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 🙏

@guhur
Copy link

guhur commented Oct 26, 2024

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

It become stable now at the beginning of the month. Would love to integrate it with sentry now :-)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 26, 2024
@lforst
Copy link
Member

lforst commented Oct 28, 2024

@guhur We are actively working on it. Tubopack may be stable but it still doesn't support a lot of features the SDK needs. You can use turbopack at any time with Sentry. Sentry just won't work well in dev mode. Turbopack for prod builds is still not stable.

lforst added a commit that referenced this issue Oct 28, 2024
This PR is in preparation for turbopack
(#8105).

In the future, `sentry.client.config.ts` will likely need to be
configured with a `"use client"` directive so that turbopack knows it
needs to be treated as a file on the client.

Our value injection loader currently always prepends the
`sentry.client.config.ts` file with statements, rendering any directives
in the file useless and crashing turbopack when the file is attempted to
be imported somewhere.

This PR detects any comments and directives on top of a file to only
inject values after.
@TheCukitoDev
Copy link

TheCukitoDev commented Oct 29, 2024

Hello, i got an error while running just pnpm dev --turbo on Next.js 15 with Sentry. This is the error:

⚠ ./node_modules/.pnpm/@[email protected]/node_modules/@sentry/node/build/cjs/sdk
Package import-in-the-middle can't be external
The request import-in-the-middle matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install import-in-the-middle from the project directory.

I did pnpm add import-in-the-middle to install the package but it doesen't makes anything

EDIT:
It don't make any compiling error but i think it should not be there

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 29, 2024
@spyl94
Copy link

spyl94 commented Oct 29, 2024

@TheCukitoDev I have fixed this issue by adding serverExternalPackages: ['@sentry/node', '@sentry/nextjs'] in my next.config.js

@lforst
Copy link
Member

lforst commented Oct 29, 2024

@spyl94 @TheCukitoDev please don't externalize the SDK. That will break it in all kinds of ways potentially. Instead add an override for your package manager to only have one import-in-the-middle package version in your dependencies. In theory Next.js shouldn't crash though.

@TheCukitoDev
Copy link

It is my mistake sorry. I added require-in-the-middle instead of import-in-the-middle but I thought it was what it tells me the error to.
Sorry.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Oct 29, 2024
@TheCukitoDev
Copy link

Again Sorry. I made a mistake. When using react 18 it needs to use import-in-the-middle but when using the actual RC of React that next supports it needs require-in-the-middle so it is the confussion. Sorry again but I think now is clear and anyone with the same issue can solve it.

lforst added a commit that referenced this issue Nov 6, 2024
…4081)

Ref: #8105

To inject build-time variables, in addition to doing so via a custom
loader, we will be injecting them via the `env` option.

Caveat: We are currently using the Next.js build ID as a release name.
This build id is passed to the `webpack` option. Since the `webpack`
option doesn't exist for turbopack we don't have access to the build ID.
For now we will simply not inject a release name, which may be better
anyhow since turbopack is currently only stable for dev.
@lforst lforst added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Improvement
Projects
Status: No status
Development

No branches or pull requests