33
44import * as fs from 'fs' ;
55import * as path from 'path' ;
6- import { escapeStringForRegex , loadModule , logger } from '@sentry/core' ;
6+ import { escapeStringForRegex , loadModule , logger , parseSemver } from '@sentry/core' ;
77import * as chalk from 'chalk' ;
88import { sync as resolveSync } from 'resolve' ;
99
@@ -22,6 +22,7 @@ import type {
2222 WebpackEntryProperty ,
2323} from './types' ;
2424import { getWebpackPluginOptions } from './webpackPluginOptions' ;
25+ import { getNextjsVersion } from './util' ;
2526
2627// Next.js runs webpack 3 times, once for the client, the server, and for edge. Because we don't want to print certain
2728// warnings 3 times, we keep track of them here.
@@ -58,7 +59,12 @@ export function constructWebpackConfigFunction(
5859 warnAboutDeprecatedConfigFiles ( projectDir , runtime ) ;
5960 }
6061 if ( runtime === 'server' ) {
61- warnAboutMissingonRequestErrorHandler ( projectDir ) ;
62+ const nextJsVersion = getNextjsVersion ( ) ;
63+ const { major } = parseSemver ( nextJsVersion || '' ) ;
64+ // was added in v15 (https://github.com/vercel/next.js/pull/67539)
65+ if ( major && major >= 15 ) {
66+ warnAboutMissingOnRequestErrorHandler ( projectDir ) ;
67+ }
6268 }
6369
6470 let rawNewConfig = { ...incomingConfig } ;
@@ -443,7 +449,7 @@ async function addSentryToClientEntryProperty(
443449 *
444450 * @param projectDir The root directory of the project, where config files would be located
445451 */
446- function warnAboutMissingonRequestErrorHandler ( projectDir : string ) : void {
452+ function warnAboutMissingOnRequestErrorHandler ( projectDir : string ) : void {
447453 const instrumentationPaths = [
448454 [ 'src' , 'instrumentation.ts' ] ,
449455 [ 'src' , 'instrumentation.js' ] ,
0 commit comments