-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): handle process.turbopack
is not supported in edge runtime
#17574
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
Closed
asionesjia
wants to merge
6
commits into
getsentry:develop
from
asionesjia:fix/process-turbopack-not-supported-in-edge-runtime
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3332576
fix: `process.turbopack` is not supported in edge runtime
asionesjia dd0e8eb
fix(nextjs): replace unsupported `process.turbopack` with `process.en…
asionesjia 0e8fc83
fix(nextjs): safely detect Turbopack in Edge/Browser environments
asionesjia 579b737
Merge branch 'develop' into fix/process-turbopack-not-supported-in-ed…
asionesjia faffeb4
Merge branch 'develop' into fix/process-turbopack-not-supported-in-ed…
asionesjia 3a13e0e
fix(nextjs): simplify Turbopack detection using process.env.TURBOPACK
asionesjia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Detect whether running under Turbopack | ||
*/ | ||
export function isTurbopack(): boolean { | ||
if (typeof process === 'undefined') return false; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
return process.env?.TURBOPACK === '1' || !!(process as any)?.turbopack; | ||
} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the comment in
src/client/index.ts
:which makes me suspect, this function needs to literally contain
process.turbopack
without any type casts or optional chain operators. If the env variable check solves something in addition, it's fine to keep. But let's maybe just try/catchprocess.turbopack
access instead of checking for definedness?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @Lms24!
You’re absolutely right about the magic string concern.
After checking the Next.js source, I found process.turbopack and process.env.TURBOPACK are always set together. Since process.env.TURBOPACK is safer in Edge Runtime and avoids the magic string issue, I’ve simplified the code to only rely on it.
You can saw the code context diff, process.turbopack and process.env.TURBOPACK
Really appreciate your feedback—please feel free to point out anything else.