Skip to content

Commit 32b6a99

Browse files
authored
fix(nextjs): Show misconfiguration warning (no instrumentation.ts) (#11266)
The warning existed, but was not called
1 parent 2774d1a commit 32b6a99

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export function constructWebpackConfigFunction(
6060
const { isServer, dev: isDev, dir: projectDir } = buildContext;
6161
const runtime = isServer ? (buildContext.nextRuntime === 'edge' ? 'edge' : 'server') : 'client';
6262

63+
if (runtime !== 'client') {
64+
warnAboutDeprecatedConfigFiles(projectDir, runtime);
65+
}
66+
6367
let rawNewConfig = { ...incomingConfig };
6468

6569
// if user has custom webpack config (which always takes the form of a function), run it so we have actual values to
@@ -508,25 +512,23 @@ async function addSentryToClientEntryProperty(
508512
* Searches for old `sentry.(server|edge).config.ts` files and warns if it finds any.
509513
*
510514
* @param projectDir The root directory of the project, where config files would be located
511-
* @param platform Either "server", "client" or "edge", so that we know which file to look for
515+
* @param platform Either "server" or "edge", so that we know which file to look for
512516
*/
513-
export function warnAboutDeprecatedConfigFiles(projectDir: string, platform: 'server' | 'client' | 'edge'): void {
517+
function warnAboutDeprecatedConfigFiles(projectDir: string, platform: 'server' | 'edge'): void {
514518
const possibilities = [`sentry.${platform}.config.ts`, `sentry.${platform}.config.js`];
515519

516520
for (const filename of possibilities) {
517521
if (fs.existsSync(path.resolve(projectDir, filename))) {
518-
if (platform === 'server' || platform === 'edge') {
519-
// eslint-disable-next-line no-console
520-
console.warn(
521-
`[@sentry/nextjs] It seems you have configured a \`${filename}\` file. You need to put this file's content into a Next.js instrumentation hook instead! Read more: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation`,
522-
);
523-
}
522+
// eslint-disable-next-line no-console
523+
console.warn(
524+
`[@sentry/nextjs] It appears you've configured a \`${filename}\` file. Please ensure to put this file's content into the \`register()\` function of a Next.js instrumentation hook instead. To ensure correct functionality of the SDK, \`Sentry.init\` must be called inside \`instrumentation.ts\`. Learn more about setting up an instrumentation hook in Next.js: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation. You can safely delete the \`${filename}\` file afterward.`,
525+
);
524526
}
525527
}
526528
}
527529

528530
/**
529-
* Searches for a `sentry.client.config.ts|js` file and returns it's file name if it finds one. (ts being prioritized)
531+
* Searches for a `sentry.client.config.ts|js` file and returns its file name if it finds one. (ts being prioritized)
530532
*
531533
* @param projectDir The root directory of the project, where config files would be located
532534
*/

0 commit comments

Comments
 (0)