-
-
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
fix(nextjs): handle process.turbopack
is not supported in edge runtime
#17574
Conversation
process.turbopack
is not supported in edge runtimeprocess.turbopack
is not supported in edge runtime
process.turbopack
is not supported in edge runtimeprocess.turbopack
is not supported in edge runtime
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.
Hey, just stepping in with an initial review. I'll leave the final review to @chargome and @RulaKhaled but I had one concern with the change. Can you take a look at that? Thanks!
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; | ||
} |
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
:
process.turbopack
is a magic string that will be replaced by Next.js
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/catch process.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.
try { | ||
// @ts-expect-error `process.turbopack` is a magic string that will be replaced by Next.js | ||
if (process.turbopack) { | ||
if (process.env.TURBOPACK) { |
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.
Bug: Turbopack Detection Regression
Replacing process.turbopack
with process.env.TURBOPACK
breaks Next.js's build-time magic string replacement for Turbopack detection. This implementation also doesn't align with the PR description, which proposed a fallback checking both process.env.TURBOPACK
and process.turbopack
to ensure detection works as expected.
Additional Locations (2)
The way to reproduce this problem is to use withSentryConfig in next.config.ts of nextjs 15.5.2(latest) and then execute next build. |
This problem is only for me, because I've used |
Summary
Fix: Replace direct usage of
process.turbopack
with a safe fallback usingprocess.env.TURBOPACK
.This resolves the error:
Changes
process.turbopack
with: