Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { constructWebpackConfigFunction } from '../webpack';
import { DEFAULT_SERVER_EXTERNAL_PACKAGES } from './constants';
import type { VercelCronsConfigResult } from './getFinalConfigObjectUtils';

const UNSUPPORTED_TURBOPACK_WARNING_SHOWN = '__SENTRY_UNSUPPORTED_TURBOPACK_WARNING_SHOWN__';

/**
* Information about the active bundler and feature support based on Next.js version.
*/
Expand Down Expand Up @@ -43,7 +45,14 @@ export function maybeWarnAboutUnsupportedTurbopack(
silent?: boolean,
): void {
// Warn if using turbopack with an unsupported Next.js version
if (!bundlerInfo.isTurbopackSupported && bundlerInfo.isTurbopack) {
if (
!bundlerInfo.isTurbopackSupported &&
bundlerInfo.isTurbopack &&
!silent &&
process.env[UNSUPPORTED_TURBOPACK_WARNING_SHOWN] !== '1'
) {
// Next.js may evaluate its config in child processes, which inherit this state from their parent.
process.env[UNSUPPORTED_TURBOPACK_WARNING_SHOWN] = '1';
getBuildLogger(silent).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.`,
);
Expand Down
8 changes: 8 additions & 0 deletions packages/nextjs/test/config/silent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const WEBPACK: BundlerInfo = { isTurbopack: false, isWebpack: true, isTurbopackS
// variants need distinct paths to both actually scan. Neither is a directory, which is what makes it log.
const NOT_A_DIRECTORY = { silent: __filename, notSilent: path.join(__dirname, 'testUtils.ts') };

beforeEach(() => {
delete process.env.__SENTRY_UNSUPPORTED_TURBOPACK_WARNING_SHOWN__;
});

afterEach(() => {
delete process.env.__SENTRY_UNSUPPORTED_TURBOPACK_WARNING_SHOWN__;
});

describe('getBuildLogger', () => {
it('forwards to the console when not silent', () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
Expand Down
26 changes: 26 additions & 0 deletions packages/nextjs/test/config/withSentryConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const EXPECTED_DEFAULT_EXTERNALS = [
];

describe('withSentryConfig', () => {
beforeEach(() => {
delete process.env.__SENTRY_UNSUPPORTED_TURBOPACK_WARNING_SHOWN__;
});

afterEach(() => {
delete process.env.__SENTRY_UNSUPPORTED_TURBOPACK_WARNING_SHOWN__;
});
Comment thread
hafzism marked this conversation as resolved.

// `next.config.js` / `next.config.mjs` get no type checking, so this warning is the only signal
// those users receive that the option is gone.
describe('removed `unstable_sentryWebpackPluginOptions`', () => {
Expand Down Expand Up @@ -1280,6 +1288,24 @@ describe('withSentryConfig', () => {
consoleWarnSpy.mockRestore();
});

it('warns only once when the config is materialized repeatedly', () => {
process.env.TURBOPACK = '1';
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.0');
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});

materializeFinalNextConfig(exportedNextConfig);
materializeFinalNextConfig(exportedNextConfig);
materializeFinalNextConfig(exportedNextConfig);

const turbopackWarnings = consoleWarnSpy.mock.calls.filter(([message]) =>
String(message).includes('WARNING: You are using the Sentry SDK with Turbopack'),
);
expect(turbopackWarnings).toHaveLength(1);

consoleWarnSpy.mockRestore();
});
Comment thread
sentry[bot] marked this conversation as resolved.

it('does not warn when Turbopack is enabled with supported Next.js version', () => {
process.env.TURBOPACK = '1';
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
Expand Down
Loading