Skip to content

Commit 556d1e3

Browse files
committed
update turbopack warnings
1 parent d7538cd commit 556d1e3

File tree

2 files changed

+214
-36
lines changed

2 files changed

+214
-36
lines changed

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -254,43 +254,19 @@ function getFinalConfigObject(
254254

255255
let nextMajor: number | undefined;
256256
const isTurbopack = process.env.TURBOPACK;
257-
let isTurbopackSupported = false;
258-
if (nextJsVersion) {
259-
const { major, minor, patch, prerelease } = parseSemver(nextJsVersion);
260-
nextMajor = major;
261-
const isSupportedVersion =
262-
major !== undefined &&
263-
minor !== undefined &&
264-
patch !== undefined &&
265-
(major > 15 ||
266-
(major === 15 && minor > 3) ||
267-
(major === 15 && minor === 3 && patch === 0 && prerelease === undefined) ||
268-
(major === 15 && minor === 3 && patch > 0));
269-
isTurbopackSupported = isSupportedVersion;
270-
const isSupportedCanary =
271-
major !== undefined &&
272-
minor !== undefined &&
273-
patch !== undefined &&
274-
prerelease !== undefined &&
275-
major === 15 &&
276-
minor === 3 &&
277-
patch === 0 &&
278-
prerelease.startsWith('canary.') &&
279-
parseInt(prerelease.split('.')[1] || '', 10) >= 28;
280-
const supportsClientInstrumentation = isSupportedCanary || isSupportedVersion;
257+
const isTurbopackSupported = supportsProductionCompileHook();
281258

282-
if (!supportsClientInstrumentation && isTurbopack) {
283-
if (process.env.NODE_ENV === 'development') {
284-
// eslint-disable-next-line no-console
285-
console.warn(
286-
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (\`next dev --turbo\`). The Sentry SDK is compatible with Turbopack on Next.js version 15.3.0 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack. Note that the SDK will continue to work for non-Turbopack production builds. This warning is only about dev-mode.`,
287-
);
288-
} else if (process.env.NODE_ENV === 'production') {
289-
// eslint-disable-next-line no-console
290-
console.warn(
291-
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack (\`next build --turbo\`). The Sentry SDK is compatible with Turbopack on Next.js version 15.3.0 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack. Note that as Turbopack is still experimental for production builds, some of the Sentry SDK features like source maps will not work. Follow this issue for progress on Sentry + Turbopack: https://github.com/getsentry/sentry-javascript/issues/8105.`,
292-
);
293-
}
259+
if (!isTurbopackSupported && isTurbopack) {
260+
if (process.env.NODE_ENV === 'development') {
261+
// eslint-disable-next-line no-console
262+
console.warn(
263+
`[@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.`,
264+
);
265+
} else if (process.env.NODE_ENV === 'production') {
266+
// eslint-disable-next-line no-console
267+
console.warn(
268+
`[@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.`,
269+
);
294270
}
295271
}
296272

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

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,4 +968,206 @@ describe('withSentryConfig', () => {
968968
expect(finalConfig.compiler?.runAfterProductionCompile).toBeInstanceOf(Function);
969969
});
970970
});
971+
972+
describe('turbopack version compatibility warnings', () => {
973+
const originalTurbopack = process.env.TURBOPACK;
974+
const originalNodeEnv = process.env.NODE_ENV;
975+
976+
afterEach(() => {
977+
vi.restoreAllMocks();
978+
process.env.TURBOPACK = originalTurbopack;
979+
// @ts-expect-error - NODE_ENV is read-only in types but we need to restore it in tests
980+
process.env.NODE_ENV = originalNodeEnv;
981+
});
982+
983+
it('warns in development mode when Turbopack is enabled with unsupported Next.js version', () => {
984+
process.env.TURBOPACK = '1';
985+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
986+
process.env.NODE_ENV = 'development';
987+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.0');
988+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
989+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
990+
991+
materializeFinalNextConfig(exportedNextConfig);
992+
993+
expect(consoleWarnSpy).toHaveBeenCalledWith(
994+
'[@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.',
995+
);
996+
997+
consoleWarnSpy.mockRestore();
998+
});
999+
1000+
it('warns in production mode when Turbopack is enabled with unsupported Next.js version', () => {
1001+
process.env.TURBOPACK = '1';
1002+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1003+
process.env.NODE_ENV = 'production';
1004+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.9');
1005+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1006+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1007+
1008+
materializeFinalNextConfig(exportedNextConfig);
1009+
1010+
expect(consoleWarnSpy).toHaveBeenCalledWith(
1011+
'[@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.',
1012+
);
1013+
1014+
consoleWarnSpy.mockRestore();
1015+
});
1016+
1017+
it('does not warn when Turbopack is enabled with supported Next.js version', () => {
1018+
process.env.TURBOPACK = '1';
1019+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1020+
process.env.NODE_ENV = 'development';
1021+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
1022+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(true);
1023+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1024+
1025+
materializeFinalNextConfig(exportedNextConfig);
1026+
1027+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1028+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1029+
);
1030+
1031+
consoleWarnSpy.mockRestore();
1032+
});
1033+
1034+
it('does not warn when Turbopack is enabled with higher supported Next.js version', () => {
1035+
process.env.TURBOPACK = '1';
1036+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1037+
process.env.NODE_ENV = 'production';
1038+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.5.0');
1039+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(true);
1040+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1041+
1042+
materializeFinalNextConfig(exportedNextConfig);
1043+
1044+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1045+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1046+
);
1047+
1048+
consoleWarnSpy.mockRestore();
1049+
});
1050+
1051+
it('does not warn when Turbopack is enabled with Next.js 16+', () => {
1052+
process.env.TURBOPACK = '1';
1053+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1054+
process.env.NODE_ENV = 'development';
1055+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('16.0.0');
1056+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(true);
1057+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1058+
1059+
materializeFinalNextConfig(exportedNextConfig);
1060+
1061+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1062+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1063+
);
1064+
1065+
consoleWarnSpy.mockRestore();
1066+
});
1067+
1068+
it('does not warn when Turbopack is not enabled', () => {
1069+
delete process.env.TURBOPACK;
1070+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1071+
process.env.NODE_ENV = 'development';
1072+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1073+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1074+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1075+
1076+
materializeFinalNextConfig(exportedNextConfig);
1077+
1078+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1079+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1080+
);
1081+
1082+
consoleWarnSpy.mockRestore();
1083+
});
1084+
1085+
it('warns even when Next.js version cannot be determined if Turbopack is unsupported', () => {
1086+
process.env.TURBOPACK = '1';
1087+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1088+
process.env.NODE_ENV = 'development';
1089+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue(undefined);
1090+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1091+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1092+
1093+
materializeFinalNextConfig(exportedNextConfig);
1094+
1095+
// Warning will still show because supportsProductionCompileHook returns false
1096+
expect(consoleWarnSpy).toHaveBeenCalledWith(
1097+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1098+
);
1099+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('You are currently on undefined'));
1100+
1101+
consoleWarnSpy.mockRestore();
1102+
});
1103+
1104+
it('warns with correct version in message for edge case versions', () => {
1105+
process.env.TURBOPACK = '1';
1106+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1107+
process.env.NODE_ENV = 'development';
1108+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.0-canary.15');
1109+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1110+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1111+
1112+
materializeFinalNextConfig(exportedNextConfig);
1113+
1114+
expect(consoleWarnSpy).toHaveBeenCalledWith(
1115+
'[@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.',
1116+
);
1117+
1118+
consoleWarnSpy.mockRestore();
1119+
});
1120+
1121+
it('does not warn in other environments besides development and production', () => {
1122+
process.env.TURBOPACK = '1';
1123+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1124+
process.env.NODE_ENV = 'test';
1125+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1126+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1127+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1128+
1129+
materializeFinalNextConfig(exportedNextConfig);
1130+
1131+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1132+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1133+
);
1134+
1135+
consoleWarnSpy.mockRestore();
1136+
});
1137+
1138+
it('handles falsy TURBOPACK environment variable', () => {
1139+
process.env.TURBOPACK = '';
1140+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1141+
process.env.NODE_ENV = 'development';
1142+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1143+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1144+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1145+
1146+
materializeFinalNextConfig(exportedNextConfig);
1147+
1148+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
1149+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1150+
);
1151+
1152+
consoleWarnSpy.mockRestore();
1153+
});
1154+
1155+
it('warns when TURBOPACK=0 (truthy string) with unsupported version', () => {
1156+
process.env.TURBOPACK = '0';
1157+
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
1158+
process.env.NODE_ENV = 'development';
1159+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1160+
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
1161+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
1162+
1163+
materializeFinalNextConfig(exportedNextConfig);
1164+
1165+
// Note: '0' is truthy in JavaScript, so this will trigger the warning
1166+
expect(consoleWarnSpy).toHaveBeenCalledWith(
1167+
expect.stringContaining('WARNING: You are using the Sentry SDK with Turbopack'),
1168+
);
1169+
1170+
consoleWarnSpy.mockRestore();
1171+
});
1172+
});
9711173
});

0 commit comments

Comments
 (0)