Skip to content

Commit 68f6654

Browse files
author
Luca Forstner
committed
beep boop
1 parent 08344da commit 68f6654

File tree

2 files changed

+75
-66
lines changed

2 files changed

+75
-66
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ export function constructWebpackConfigFunction(
339339
// be fixed by using `bind`, but this is way simpler.)
340340
const origEntryProperty = newConfig.entry;
341341
newConfig.entry = async () => addSentryToClientEntryProperty(origEntryProperty, buildContext);
342+
343+
const clientSentryConfigFileName = getClientSentryConfigFile(projectDir);
344+
if (clientSentryConfigFileName?.includes('sentry.client.config')) {
345+
// eslint-disable-next-line no-console
346+
console.warn(
347+
`[@sentry/nextjs] DEPRECATION WARNING: It is recommended renaming your \`${clientSentryConfigFileName}\` file, or moving its content to \`instrumentation-client.ts\`. When using Turbopack \`${clientSentryConfigFileName}\` will no longer work. Read more about the \`instrumentation-client.ts\` file: https://nextjs.org/docs/app/api-reference/config/next-config-js/clientInstrumentationHook`,
348+
);
349+
}
342350
}
343351

344352
// We don't want to do any webpack plugin stuff OR any source maps stuff in dev mode.
@@ -430,9 +438,17 @@ async function addSentryToClientEntryProperty(
430438
typeof currentEntryProperty === 'function' ? await currentEntryProperty() : { ...currentEntryProperty };
431439

432440
const clientSentryConfigFileName = getClientSentryConfigFile(projectDir);
441+
const instrumentationClientFileName = getInstrumentationClientFile(projectDir);
433442

434-
// we need to turn the filename into a path so webpack can find it
435-
const filesToInject = clientSentryConfigFileName ? [`./${clientSentryConfigFileName}`] : [];
443+
const filesToInject = [];
444+
if (clientSentryConfigFileName) {
445+
// we need to turn the filename into a path so webpack can find it
446+
filesToInject.push(`./${clientSentryConfigFileName}`);
447+
}
448+
if (instrumentationClientFileName) {
449+
// we need to turn the filename into a path so webpack can find it
450+
filesToInject.push(`./${instrumentationClientFileName}`);
451+
}
436452

437453
// inject into all entry points which might contain user's code
438454
for (const entryPointName in newEntryProperty) {
@@ -526,18 +542,31 @@ function warnAboutDeprecatedConfigFiles(
526542
}
527543

528544
/**
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)
545+
* Searches for a `sentry.client.config.ts|js` file and returns its file name if it finds one. (ts being prioritized)
530546
*
531547
* @param projectDir The root directory of the project, where config files would be located
532548
*/
533549
function getClientSentryConfigFile(projectDir: string): string | void {
550+
const possibilities = ['sentry.client.config.ts', 'sentry.client.config.js'];
551+
552+
for (const filename of possibilities) {
553+
if (fs.existsSync(path.resolve(projectDir, filename))) {
554+
return filename;
555+
}
556+
}
557+
}
558+
559+
/**
560+
* Searches for a `instrumentation-client.ts|js` file and returns its file name if it finds one. (ts being prioritized)
561+
*
562+
* @param projectDir The root directory of the project, where config files would be located
563+
*/
564+
function getInstrumentationClientFile(projectDir: string): string | void {
534565
const possibilities = [
535-
['instrumentation-client.ts'],
566+
['src', 'instrumentation-client.js'],
536567
['src', 'instrumentation-client.ts'],
537568
['instrumentation-client.js'],
538-
['src', 'instrumentation-client.js'],
539-
['sentry.client.config.ts'],
540-
['sentry.client.config.js'],
569+
['instrumentation-client.ts'],
541570
];
542571

543572
for (const pathParts of possibilities) {

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -153,69 +153,49 @@ function getFinalConfigObject(
153153
}
154154
}
155155

156-
if (process.env.TURBOPACK) {
157-
// TODO: Emit different warning when on Next.js version that supports instrumentation-client.ts
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-
}
156+
if (nextJsVersion) {
157+
const { major, minor, patch, prerelease } = parseSemver(nextJsVersion);
158+
const isSupportedVersion =
159+
major !== undefined &&
160+
minor !== undefined &&
161+
patch !== undefined &&
162+
(major > 15 ||
163+
(major === 15 && minor > 3) ||
164+
(major === 15 && minor === 3 && patch > 0 && prerelease === undefined));
165+
const isSupportedCanary =
166+
major !== undefined &&
167+
minor !== undefined &&
168+
patch !== undefined &&
169+
prerelease !== undefined &&
170+
major === 15 &&
171+
minor === 3 &&
172+
patch === 0 &&
173+
prerelease.startsWith('canary.') &&
174+
parseInt(prerelease.split('.')[1] || '', 10) >= 8;
175+
const supportsClientInstrumentation = isSupportedCanary || isSupportedVersion;
176+
177+
if (supportsClientInstrumentation) {
214178
incomingUserNextConfigObject.experimental = {
215-
instrumentationHook: true,
179+
clientInstrumentationHook: true,
216180
...incomingUserNextConfigObject.experimental,
217181
};
218182
}
183+
} else {
184+
if (
185+
!(
186+
incomingUserNextConfigObject.experimental &&
187+
'clientInstrumentationHook' in incomingUserNextConfigObject.experimental
188+
)
189+
) {
190+
// eslint-disable-next-line no-console
191+
console.log(
192+
'[@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`.',
193+
);
194+
}
195+
incomingUserNextConfigObject.experimental = {
196+
clientInstrumentationHook: true,
197+
...incomingUserNextConfigObject.experimental,
198+
};
219199
}
220200

221201
if (incomingUserNextConfigObject.experimental?.clientInstrumentationHook === false) {

0 commit comments

Comments
 (0)