Skip to content

Commit 08344da

Browse files
author
Luca Forstner
committed
Warning bonanza
1 parent ebd7d09 commit 08344da

File tree

3 files changed

+79
-19
lines changed

3 files changed

+79
-19
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type NextConfigObject = {
4444
// Next.js experimental options
4545
experimental?: {
4646
instrumentationHook?: boolean;
47+
clientInstrumentationHook?: boolean;
4748
clientTraceMetadata?: string[];
4849
};
4950
productionBrowserSourceMaps?: boolean;

packages/nextjs/src/config/webpack.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,23 @@ function warnAboutDeprecatedConfigFiles(
526526
}
527527

528528
/**
529-
* Searches for a `sentry.client.config.ts|js` file and returns its file name if it finds one. (ts being prioritized)
529+
* Searches for a `instrumentation-client.ts|js` or `sentry.client.config.ts|js` file and returns its file name if it finds one. (ts being prioritized)
530530
*
531531
* @param projectDir The root directory of the project, where config files would be located
532532
*/
533-
export function getClientSentryConfigFile(projectDir: string): string | void {
533+
function getClientSentryConfigFile(projectDir: string): string | void {
534534
const possibilities = [
535-
'sentry.client.config.ts',
536-
'sentry.client.config.js',
537-
'instrumentation-client.ts',
538-
'src/instrumentation-client.ts',
535+
['instrumentation-client.ts'],
536+
['src', 'instrumentation-client.ts'],
537+
['instrumentation-client.js'],
538+
['src', 'instrumentation-client.js'],
539+
['sentry.client.config.ts'],
540+
['sentry.client.config.js'],
539541
];
540542

541-
for (const filename of possibilities) {
542-
if (fs.existsSync(path.resolve(projectDir, filename))) {
543-
return filename;
543+
for (const pathParts of possibilities) {
544+
if (fs.existsSync(path.resolve(projectDir, ...pathParts))) {
545+
return path.join(...pathParts);
544546
}
545547
}
546548
}

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,76 @@ function getFinalConfigObject(
155155

156156
if (process.env.TURBOPACK) {
157157
// TODO: Emit different warning when on Next.js version that supports instrumentation-client.ts
158-
159-
if (!process.env.SENTRY_SUPPRESS_TURBOPACK_WARNING) {
160-
// eslint-disable-next-line no-console
161-
console.warn(
162-
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with \`next ${
163-
process.env.NODE_ENV === 'development' ? 'dev' : 'build'
164-
} --turbo\`. The Sentry SDK doesn't yet fully support Turbopack. The SDK will not be loaded in the browser, and serverside instrumentation will be inaccurate or incomplete. ${
165-
process.env.NODE_ENV === 'development' ? 'Production builds without `--turbo` will still fully work. ' : ''
166-
}If you are just trying out Sentry or attempting to configure the SDK, we recommend temporarily removing the \`--turbo\` flag while you are developing locally. Follow this issue for progress on Sentry + Turbopack: https://github.com/getsentry/sentry-javascript/issues/8105. (You can suppress this warning by setting SENTRY_SUPPRESS_TURBOPACK_WARNING=1 as environment variable)`,
167-
);
158+
if (nextJsVersion) {
159+
const { major, minor, patch, prerelease } = parseSemver(nextJsVersion);
160+
const isSupportedVersion =
161+
major !== undefined &&
162+
minor !== undefined &&
163+
patch !== undefined &&
164+
(major > 15 ||
165+
(major === 15 && minor > 3) ||
166+
(major === 15 && minor === 3 && patch > 0 && prerelease === undefined));
167+
const isSupportedCanary =
168+
major !== undefined &&
169+
minor !== undefined &&
170+
patch !== undefined &&
171+
prerelease !== undefined &&
172+
major === 15 &&
173+
minor === 3 &&
174+
patch === 0 &&
175+
prerelease.startsWith('canary.') &&
176+
parseInt(prerelease.split('.')[1] || '', 10) >= 8;
177+
const supportsClientInstrumentation = isSupportedCanary || isSupportedVersion;
178+
179+
if (supportsClientInstrumentation) {
180+
incomingUserNextConfigObject.experimental = {
181+
clientInstrumentationHook: true,
182+
...incomingUserNextConfigObject.experimental,
183+
};
184+
185+
if (process.env.NODE_ENV === 'production' && !process.env.SENTRY_SUPPRESS_TURBOPACK_WARNING) {
186+
// eslint-disable-next-line no-console
187+
console.warn(
188+
'[@sentry/nextjs] WARNING: You are using the Sentry SDK with TurboPack (`next build --turbo`). 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. (You can suppress this warning by setting SENTRY_SUPPRESS_TURBOPACK_WARNING=1 as environment variable)',
189+
);
190+
}
191+
} else if (process.env.NODE_ENV === 'development') {
192+
// eslint-disable-next-line no-console
193+
console.warn(
194+
`[@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.`,
195+
);
196+
} else if (process.env.NODE_ENV === 'production') {
197+
// eslint-disable-next-line no-console
198+
console.warn(
199+
`[@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.`,
200+
);
201+
}
202+
} else {
203+
if (
204+
!(
205+
incomingUserNextConfigObject.experimental &&
206+
'clientInstrumentationHook' in incomingUserNextConfigObject.experimental
207+
)
208+
) {
209+
// eslint-disable-next-line no-console
210+
console.log(
211+
'[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. If you are using Next.js versions earlier than 15.3.0, Next.js will probably show you a warning about the `experimental.clientInstrumentationHook` being set. To silence the warning, explicitly set the `experimental.clientInstrumentationHook` option in your `next.config.(js|mjs|ts)` to `undefined`.',
212+
);
213+
}
214+
incomingUserNextConfigObject.experimental = {
215+
instrumentationHook: true,
216+
...incomingUserNextConfigObject.experimental,
217+
};
168218
}
169219
}
170220

221+
if (incomingUserNextConfigObject.experimental?.clientInstrumentationHook === false) {
222+
// eslint-disable-next-line no-console
223+
console.warn(
224+
'[@sentry/nextjs] WARNING: You set the `experimental.clientInstrumentationHook` option to `false`. Note that Sentry will not be initialized if you did not set it up inside `instrumentation-client.(js|ts)`.',
225+
);
226+
}
227+
171228
const releaseName = userSentryOptions.release?.name ?? getSentryRelease() ?? getGitRevision();
172229

173230
return {

0 commit comments

Comments
 (0)