Skip to content
Prev Previous commit
Next Next commit
update detection
  • Loading branch information
chargome committed Oct 6, 2025
commit 3e8681e449be3992fc166048a5447a0076bda854
35 changes: 16 additions & 19 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
NextConfigObject,
SentryBuildOptions,
} from './types';
import { getNextjsVersion, supportsProductionCompileHook } from './util';
import { detectActiveBundler, getNextjsVersion, supportsProductionCompileHook } from './util';
import { constructWebpackConfigFunction } from './webpack';

let showedExportModeTunnelWarning = false;
Expand Down Expand Up @@ -258,28 +258,24 @@ function getFinalConfigObject(
nextMajor = major;
}

const isTurbopack = process.env.TURBOPACK;
const activeBundler = detectActiveBundler(nextJsVersion);
const isTurbopack = activeBundler === 'turbopack';
const isWebpack = activeBundler === 'webpack';
const isTurbopackSupported = supportsProductionCompileHook(nextJsVersion ?? '');

// Warn if using turbopack with an unsupported Next.js version
if (!isTurbopackSupported && isTurbopack) {
if (process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn(
`[@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.`,
);
} else if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.warn(
`[@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.`,
);
}
// eslint-disable-next-line no-console
console.warn(
`[@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.`,
);
}

// webpack case
// Webpack case - warn if trying to use runAfterProductionCompile hook with unsupported Next.js version
if (
userSentryOptions.useRunAfterProductionCompileHook &&
!supportsProductionCompileHook(nextJsVersion ?? '') &&
!isTurbopack
isWebpack
) {
// eslint-disable-next-line no-console
console.warn(
Expand Down Expand Up @@ -367,17 +363,18 @@ function getFinalConfigObject(
],
},
}),
webpack:
isTurbopack || userSentryOptions.disableSentryWebpackConfig
? incomingUserNextConfigObject.webpack // just return the original webpack config
: constructWebpackConfigFunction({
...(isWebpack && !userSentryOptions.disableSentryWebpackConfig
? {
webpack: constructWebpackConfigFunction({
userNextConfig: incomingUserNextConfigObject,
userSentryOptions,
releaseName,
routeManifest,
nextJsVersion,
useRunAfterProductionCompileHook: shouldUseRunAfterProductionCompileHook,
}),
}
: {}),
Comment thread
cursor[bot] marked this conversation as resolved.
...(isTurbopackSupported && isTurbopack
? {
turbopack: constructTurbopackConfig({
Expand Down
23 changes: 3 additions & 20 deletions packages/nextjs/test/config/withSentryConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ describe('withSentryConfig', () => {
materializeFinalNextConfig(exportedNextConfig);

expect(consoleWarnSpy).toHaveBeenCalledWith(
'[@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.',
'[@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.',
);

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

expect(consoleWarnSpy).toHaveBeenCalledWith(
'[@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.',
'[@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.',
);

consoleWarnSpy.mockRestore();
Expand Down Expand Up @@ -1115,24 +1115,7 @@ describe('withSentryConfig', () => {
materializeFinalNextConfig(exportedNextConfig);

expect(consoleWarnSpy).toHaveBeenCalledWith(
'[@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.',
);

consoleWarnSpy.mockRestore();
});

it('does not warn in other environments besides development and production', () => {
process.env.TURBOPACK = '1';
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
process.env.NODE_ENV = 'test';
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

materializeFinalNextConfig(exportedNextConfig);

expect(consoleWarnSpy).not.toHaveBeenCalledWith(
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
'[@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.',
);

consoleWarnSpy.mockRestore();
Expand Down