Skip to content

Commit 354806e

Browse files
committed
inject sentry.x.config.js into pages/_error when building server bundle
1 parent e92ad68 commit 354806e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async function addSentryToEntryProperty(
144144

145145
// inject into all entry points which might contain user's code
146146
for (const entryPointName in newEntryProperty) {
147-
if (shouldAddSentryToEntryPoint(entryPointName)) {
147+
if (shouldAddSentryToEntryPoint(entryPointName, isServer)) {
148148
addFilesToExistingEntryPoint(newEntryProperty, entryPointName, filesToInject);
149149
}
150150
}
@@ -251,10 +251,15 @@ function checkWebpackPluginOverrides(
251251
* Determine if this is an entry point into which both `Sentry.init()` code and the release value should be injected
252252
*
253253
* @param entryPointName The name of the entry point in question
254+
* @param isServer Whether or not this function is being called in the context of a server build
254255
* @returns `true` if sentry code should be injected, and `false` otherwise
255256
*/
256-
function shouldAddSentryToEntryPoint(entryPointName: string): boolean {
257-
return entryPointName === 'pages/_app' || entryPointName.includes('pages/api');
257+
function shouldAddSentryToEntryPoint(entryPointName: string, isServer: boolean): boolean {
258+
return (
259+
entryPointName === 'pages/_app' ||
260+
entryPointName.includes('pages/api') ||
261+
(isServer && entryPointName === 'pages/_error')
262+
);
258263
}
259264

260265
/**
@@ -295,7 +300,7 @@ export function getWebpackPluginOptions(
295300
configFile: hasSentryProperties ? 'sentry.properties' : undefined,
296301
stripPrefix: ['webpack://_N_E/'],
297302
urlPrefix,
298-
entries: shouldAddSentryToEntryPoint,
303+
entries: (entryPointName: string) => shouldAddSentryToEntryPoint(entryPointName, isServer),
299304
release: getSentryRelease(buildId),
300305
dryRun: isDev,
301306
});

0 commit comments

Comments
 (0)