@@ -290,7 +290,7 @@ async function addSentryToEntryProperty(
290
290
// we know is that it won't have gotten *simpler* in form, so we only need to worry about the object and function
291
291
// options. See https://webpack.js.org/configuration/entry-context/#entry.
292
292
293
- const { isServer, dir : projectDir } = buildContext ;
293
+ const { isServer, dir : projectDir , dev : isDev } = buildContext ;
294
294
295
295
const newEntryProperty =
296
296
typeof currentEntryProperty === 'function' ? await currentEntryProperty ( ) : { ...currentEntryProperty } ;
@@ -303,7 +303,7 @@ async function addSentryToEntryProperty(
303
303
304
304
// inject into all entry points which might contain user's code
305
305
for ( const entryPointName in newEntryProperty ) {
306
- if ( shouldAddSentryToEntryPoint ( entryPointName , isServer , userSentryOptions . excludeServerRoutes ) ) {
306
+ if ( shouldAddSentryToEntryPoint ( entryPointName , isServer , userSentryOptions . excludeServerRoutes , isDev ) ) {
307
307
addFilesToExistingEntryPoint ( newEntryProperty , entryPointName , filesToInject ) ;
308
308
} else {
309
309
if (
@@ -429,14 +429,25 @@ function shouldAddSentryToEntryPoint(
429
429
entryPointName : string ,
430
430
isServer : boolean ,
431
431
excludeServerRoutes : Array < string | RegExp > = [ ] ,
432
+ isDev : boolean ,
432
433
) : boolean {
433
434
// On the server side, by default we inject the `Sentry.init()` code into every page (with a few exceptions).
434
435
if ( isServer ) {
435
436
const entryPointRoute = entryPointName . replace ( / ^ p a g e s / , '' ) ;
437
+
438
+ // User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
439
+ // which don't have the `pages` prefix.)
440
+ if ( stringMatchesSomePattern ( entryPointRoute , excludeServerRoutes , true ) ) {
441
+ return false ;
442
+ }
443
+
444
+ // In dev mode, page routes aren't considered entrypoints so we inject the init call in the `/_app` entrypoint which
445
+ // always exists, even if the user didn't add a `_app` page themselves
446
+ if ( isDev ) {
447
+ return entryPointRoute === '/_app' ;
448
+ }
449
+
436
450
if (
437
- // User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
438
- // which don't have the `pages` prefix.)
439
- stringMatchesSomePattern ( entryPointRoute , excludeServerRoutes , true ) ||
440
451
// All non-API pages contain both of these components, and we don't want to inject more than once, so as long as
441
452
// we're doing the individual pages, it's fine to skip these. (Note: Even if a given user doesn't have either or
442
453
// both of these in their `pages/` folder, they'll exist as entrypoints because nextjs will supply default
@@ -516,7 +527,7 @@ export function getWebpackPluginOptions(
516
527
stripPrefix : [ 'webpack://_N_E/' ] ,
517
528
urlPrefix,
518
529
entries : ( entryPointName : string ) =>
519
- shouldAddSentryToEntryPoint ( entryPointName , isServer , userSentryOptions . excludeServerRoutes ) ,
530
+ shouldAddSentryToEntryPoint ( entryPointName , isServer , userSentryOptions . excludeServerRoutes , isDev ) ,
520
531
release : getSentryRelease ( buildId ) ,
521
532
dryRun : isDev ,
522
533
} ) ;
0 commit comments