Skip to content

Commit 3e8681e

Browse files
committed
update detection
1 parent d209fac commit 3e8681e

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
NextConfigObject,
1616
SentryBuildOptions,
1717
} from './types';
18-
import { getNextjsVersion, supportsProductionCompileHook } from './util';
18+
import { detectActiveBundler, getNextjsVersion, supportsProductionCompileHook } from './util';
1919
import { constructWebpackConfigFunction } from './webpack';
2020

2121
let showedExportModeTunnelWarning = false;
@@ -258,28 +258,24 @@ function getFinalConfigObject(
258258
nextMajor = major;
259259
}
260260

261-
const isTurbopack = process.env.TURBOPACK;
261+
const activeBundler = detectActiveBundler(nextJsVersion);
262+
const isTurbopack = activeBundler === 'turbopack';
263+
const isWebpack = activeBundler === 'webpack';
262264
const isTurbopackSupported = supportsProductionCompileHook(nextJsVersion ?? '');
263265

266+
// Warn if using turbopack with an unsupported Next.js version
264267
if (!isTurbopackSupported && isTurbopack) {
265-
if (process.env.NODE_ENV === 'development') {
266-
// eslint-disable-next-line no-console
267-
console.warn(
268-
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (\`next dev --turbopack\`). The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.`,
269-
);
270-
} else if (process.env.NODE_ENV === 'production') {
271-
// eslint-disable-next-line no-console
272-
console.warn(
273-
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (\`next build --turbopack\`). The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.`,
274-
);
275-
}
268+
// eslint-disable-next-line no-console
269+
console.warn(
270+
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack. The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.`,
271+
);
276272
}
277273

278-
// webpack case
274+
// Webpack case - warn if trying to use runAfterProductionCompile hook with unsupported Next.js version
279275
if (
280276
userSentryOptions.useRunAfterProductionCompileHook &&
281277
!supportsProductionCompileHook(nextJsVersion ?? '') &&
282-
!isTurbopack
278+
isWebpack
283279
) {
284280
// eslint-disable-next-line no-console
285281
console.warn(
@@ -367,17 +363,18 @@ function getFinalConfigObject(
367363
],
368364
},
369365
}),
370-
webpack:
371-
isTurbopack || userSentryOptions.disableSentryWebpackConfig
372-
? incomingUserNextConfigObject.webpack // just return the original webpack config
373-
: constructWebpackConfigFunction({
366+
...(isWebpack && !userSentryOptions.disableSentryWebpackConfig
367+
? {
368+
webpack: constructWebpackConfigFunction({
374369
userNextConfig: incomingUserNextConfigObject,
375370
userSentryOptions,
376371
releaseName,
377372
routeManifest,
378373
nextJsVersion,
379374
useRunAfterProductionCompileHook: shouldUseRunAfterProductionCompileHook,
380375
}),
376+
}
377+
: {}),
381378
...(isTurbopackSupported && isTurbopack
382379
? {
383380
turbopack: constructTurbopackConfig({

packages/nextjs/test/config/withSentryConfig.test.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ describe('withSentryConfig', () => {
994994
materializeFinalNextConfig(exportedNextConfig);
995995

996996
expect(consoleWarnSpy).toHaveBeenCalledWith(
997-
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (`next dev --turbopack`). The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.4.0. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
997+
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack. The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.4.0. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
998998
);
999999

10001000
consoleWarnSpy.mockRestore();
@@ -1011,7 +1011,7 @@ describe('withSentryConfig', () => {
10111011
materializeFinalNextConfig(exportedNextConfig);
10121012

10131013
expect(consoleWarnSpy).toHaveBeenCalledWith(
1014-
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (`next build --turbopack`). The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.3.9. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
1014+
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack. The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.3.9. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
10151015
);
10161016

10171017
consoleWarnSpy.mockRestore();
@@ -1115,24 +1115,7 @@ describe('withSentryConfig', () => {
11151115
materializeFinalNextConfig(exportedNextConfig);
11161116

11171117
expect(consoleWarnSpy).toHaveBeenCalledWith(
1118-
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (`next dev --turbopack`). The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.4.0-canary.15. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
1119-
);
1120-
1121-
consoleWarnSpy.mockRestore();
1122-
});
1123-
1124-
it('does not warn in other environments besides development and production', () => {
1125-
process.env.TURBOPACK = '1';
1126-
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1127-
process.env.NODE_ENV = 'test';
1128-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
1129-
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1130-
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1131-
1132-
materializeFinalNextConfig(exportedNextConfig);
1133-
1134-
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1135-
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1118+
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack. The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on 15.4.0-canary.15. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.',
11361119
);
11371120

11381121
consoleWarnSpy.mockRestore();

0 commit comments

Comments
 (0)