Skip to content

Commit 0e8fc83

Browse files
committed
fix(nextjs): safely detect Turbopack in Edge/Browser environments
1 parent dd0e8eb commit 0e8fc83

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function init(options: BrowserOptions): Client | undefined {
7878
}
7979

8080
try {
81-
if (isTurbopack) {
81+
if (isTurbopack()) {
8282
getGlobalScope().setTag('turbopack', true);
8383
}
8484
} catch {
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
export const isTurbopack = process.env.TURBOPACK === '1' || (typeof process !== 'undefined' && 'turbopack' in process && process.turbopack);
1+
/**
2+
* Detect whether running under Turbopack
3+
*/
4+
export function isTurbopack(): boolean {
5+
if (typeof process === 'undefined') return false;
6+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
7+
return process.env?.TURBOPACK === '1' || !!(process as any)?.turbopack;
8+
}

packages/nextjs/src/edge/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function init(options: VercelEdgeOptions = {}): void {
9696
});
9797

9898
try {
99-
if (isTurbopack) {
99+
if (isTurbopack()) {
100100
getGlobalScope().setTag('turbopack', true);
101101
}
102102
} catch {

packages/nextjs/src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export function init(options: NodeOptions): NodeClient | undefined {
369369
}
370370

371371
try {
372-
if (isTurbopack) {
372+
if (isTurbopack()) {
373373
getGlobalScope().setTag('turbopack', true);
374374
}
375375
} catch {

0 commit comments

Comments
 (0)