Skip to content

Commit bb40be1

Browse files
authored
feat(nextjs): Update default ignore list for sourcemaps (#18938)
- adds more framework internals to the default ignore list (these will never emit sourcemaps and we just waste time processing these files) - updates ignore list to use glob patterns as this is the only way the cli properly picks them up closes #18872
1 parent 40a814d commit bb40be1

3 files changed

Lines changed: 145 additions & 5 deletions

File tree

packages/nextjs/src/config/getBuildPluginOptions.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const FILE_PATTERNS = {
3737
FRAMEWORK_CHUNKS_DOT: 'static/chunks/framework.*',
3838
POLYFILLS_CHUNKS: 'static/chunks/polyfills-*',
3939
WEBPACK_CHUNKS: 'static/chunks/webpack-*',
40+
PAGE_CLIENT_REFERENCE_MANIFEST: '**/page_client-reference-manifest.js',
41+
SERVER_REFERENCE_MANIFEST: '**/server-reference-manifest.js',
42+
NEXT_FONT_MANIFEST: '**/next-font-manifest.js',
43+
MIDDLEWARE_BUILD_MANIFEST: '**/middleware-build-manifest.js',
44+
INTERCEPTION_ROUTE_REWRITE_MANIFEST: '**/interception-route-rewrite-manifest.js',
45+
ROUTE_CLIENT_REFERENCE_MANIFEST: '**/route_client-reference-manifest.js',
46+
MIDDLEWARE_REACT_LOADABLE_MANIFEST: '**/middleware-react-loadable-manifest.js',
4047
} as const;
4148

4249
// Source map file extensions to delete
@@ -142,6 +149,16 @@ function createSourcemapUploadIgnorePattern(
142149
path.posix.join(normalizedDistPath, FILE_PATTERNS.FRAMEWORK_CHUNKS_DOT),
143150
path.posix.join(normalizedDistPath, FILE_PATTERNS.POLYFILLS_CHUNKS),
144151
path.posix.join(normalizedDistPath, FILE_PATTERNS.WEBPACK_CHUNKS),
152+
// Next.js internal manifest files that don't have source maps
153+
// These files are auto-generated by Next.js and do not contain user code.
154+
// Ignoring them prevents "Could not determine source map reference" warnings.
155+
FILE_PATTERNS.PAGE_CLIENT_REFERENCE_MANIFEST,
156+
FILE_PATTERNS.SERVER_REFERENCE_MANIFEST,
157+
FILE_PATTERNS.NEXT_FONT_MANIFEST,
158+
FILE_PATTERNS.MIDDLEWARE_BUILD_MANIFEST,
159+
FILE_PATTERNS.INTERCEPTION_ROUTE_REWRITE_MANIFEST,
160+
FILE_PATTERNS.ROUTE_CLIENT_REFERENCE_MANIFEST,
161+
FILE_PATTERNS.MIDDLEWARE_REACT_LOADABLE_MANIFEST,
145162
);
146163

147164
return ignore;
@@ -216,6 +233,20 @@ function createReleaseConfig(
216233
};
217234
}
218235

236+
/**
237+
* Merges default ignore patterns with user-provided ignore patterns.
238+
* User patterns are appended to the defaults to ensure internal Next.js
239+
* files are always ignored while allowing users to add additional patterns.
240+
*/
241+
function mergeIgnorePatterns(defaultPatterns: string[], userPatterns: string | string[] | undefined): string[] {
242+
if (!userPatterns) {
243+
return defaultPatterns;
244+
}
245+
246+
const userPatternsArray = Array.isArray(userPatterns) ? userPatterns : [userPatterns];
247+
return [...defaultPatterns, ...userPatternsArray];
248+
}
249+
219250
/**
220251
* Get Sentry Build Plugin options for both webpack and turbopack builds.
221252
* These options can be used in two ways:
@@ -239,7 +270,6 @@ export function getBuildPluginOptions({
239270
// glob characters. This clashes with Windows path separators.
240271
// See: https://www.npmjs.com/package/glob
241272
const normalizedDistDirAbsPath = normalizePathForGlob(distDirAbsPath);
242-
243273
const loggerPrefix = LOGGER_PREFIXES[buildTool];
244274
const widenClientFileUpload = sentryBuildOptions.widenClientFileUpload ?? false;
245275
const deleteSourcemapsAfterUpload = sentryBuildOptions.sourcemaps?.deleteSourcemapsAfterUpload ?? false;
@@ -252,6 +282,8 @@ export function getBuildPluginOptions({
252282

253283
const sourcemapUploadIgnore = createSourcemapUploadIgnorePattern(normalizedDistDirAbsPath, widenClientFileUpload);
254284

285+
const finalIgnorePatterns = mergeIgnorePatterns(sourcemapUploadIgnore, sentryBuildOptions.sourcemaps?.ignore);
286+
255287
const filesToDeleteAfterUpload = createFilesToDeleteAfterUploadPattern(
256288
normalizedDistDirAbsPath,
257289
buildTool,
@@ -281,7 +313,7 @@ export function getBuildPluginOptions({
281313
disable: skipSourcemapsUpload ? true : (sentryBuildOptions.sourcemaps?.disable ?? false),
282314
rewriteSources: rewriteWebpackSources,
283315
assets: sentryBuildOptions.sourcemaps?.assets ?? sourcemapUploadAssets,
284-
ignore: sentryBuildOptions.sourcemaps?.ignore ?? sourcemapUploadIgnore,
316+
ignore: finalIgnorePatterns,
285317
filesToDeleteAfterUpload,
286318
...sentryBuildOptions.webpack?.unstable_sentryWebpackPluginOptions?.sourcemaps,
287319
},

packages/nextjs/src/config/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ export type SentryBuildOptions = {
261261
/**
262262
* A glob or an array of globs that specifies which build artifacts should not be uploaded to Sentry.
263263
*
264-
* Default: `[]`
264+
* The SDK automatically ignores Next.js internal files that don't have source maps (such as manifest files)
265+
* to prevent "Could not determine source map" warnings. Your custom patterns are merged with these defaults.
265266
*
266267
* The globbing patterns follow the implementation of the `glob` package. (https://www.npmjs.com/package/glob)
267268
*

packages/nextjs/test/config/getBuildPluginOptions.test.ts

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ describe('getBuildPluginOptions', () => {
3333
'/path/to/.next/static/chunks/framework.*',
3434
'/path/to/.next/static/chunks/polyfills-*',
3535
'/path/to/.next/static/chunks/webpack-*',
36+
'**/page_client-reference-manifest.js',
37+
'**/server-reference-manifest.js',
38+
'**/next-font-manifest.js',
39+
'**/middleware-build-manifest.js',
40+
'**/interception-route-rewrite-manifest.js',
41+
'**/route_client-reference-manifest.js',
42+
'**/middleware-react-loadable-manifest.js',
3643
],
3744
filesToDeleteAfterUpload: undefined,
3845
rewriteSources: expect.any(Function),
@@ -121,6 +128,13 @@ describe('getBuildPluginOptions', () => {
121128
'/path/to/.next/static/chunks/framework.*',
122129
'/path/to/.next/static/chunks/polyfills-*',
123130
'/path/to/.next/static/chunks/webpack-*',
131+
'**/page_client-reference-manifest.js',
132+
'**/server-reference-manifest.js',
133+
'**/next-font-manifest.js',
134+
'**/middleware-build-manifest.js',
135+
'**/interception-route-rewrite-manifest.js',
136+
'**/route_client-reference-manifest.js',
137+
'**/middleware-react-loadable-manifest.js',
124138
]);
125139
expect(result.reactComponentAnnotation).toBeDefined();
126140
});
@@ -142,6 +156,13 @@ describe('getBuildPluginOptions', () => {
142156
'/path/to/.next/static/chunks/framework.*',
143157
'/path/to/.next/static/chunks/polyfills-*',
144158
'/path/to/.next/static/chunks/webpack-*',
159+
'**/page_client-reference-manifest.js',
160+
'**/server-reference-manifest.js',
161+
'**/next-font-manifest.js',
162+
'**/middleware-build-manifest.js',
163+
'**/interception-route-rewrite-manifest.js',
164+
'**/route_client-reference-manifest.js',
165+
'**/middleware-react-loadable-manifest.js',
145166
]);
146167
});
147168

@@ -161,6 +182,13 @@ describe('getBuildPluginOptions', () => {
161182
'/path/to/.next/static/chunks/framework.*',
162183
'/path/to/.next/static/chunks/polyfills-*',
163184
'/path/to/.next/static/chunks/webpack-*',
185+
'**/page_client-reference-manifest.js',
186+
'**/server-reference-manifest.js',
187+
'**/next-font-manifest.js',
188+
'**/middleware-build-manifest.js',
189+
'**/interception-route-rewrite-manifest.js',
190+
'**/route_client-reference-manifest.js',
191+
'**/middleware-react-loadable-manifest.js',
164192
]);
165193
expect(result.reactComponentAnnotation).toBeDefined();
166194
});
@@ -181,6 +209,13 @@ describe('getBuildPluginOptions', () => {
181209
'/path/to/.next/static/chunks/framework.*',
182210
'/path/to/.next/static/chunks/polyfills-*',
183211
'/path/to/.next/static/chunks/webpack-*',
212+
'**/page_client-reference-manifest.js',
213+
'**/server-reference-manifest.js',
214+
'**/next-font-manifest.js',
215+
'**/middleware-build-manifest.js',
216+
'**/interception-route-rewrite-manifest.js',
217+
'**/route_client-reference-manifest.js',
218+
'**/middleware-react-loadable-manifest.js',
184219
]);
185220
expect(result.reactComponentAnnotation).toBeDefined();
186221
});
@@ -205,6 +240,13 @@ describe('getBuildPluginOptions', () => {
205240
'/path/to/.next/static/chunks/framework.*',
206241
'/path/to/.next/static/chunks/polyfills-*',
207242
'/path/to/.next/static/chunks/webpack-*',
243+
'**/page_client-reference-manifest.js',
244+
'**/server-reference-manifest.js',
245+
'**/next-font-manifest.js',
246+
'**/middleware-build-manifest.js',
247+
'**/interception-route-rewrite-manifest.js',
248+
'**/route_client-reference-manifest.js',
249+
'**/middleware-react-loadable-manifest.js',
208250
]);
209251
expect(result.reactComponentAnnotation).toBeUndefined();
210252
});
@@ -228,6 +270,13 @@ describe('getBuildPluginOptions', () => {
228270
'/path/to/.next/static/chunks/framework.*',
229271
'/path/to/.next/static/chunks/polyfills-*',
230272
'/path/to/.next/static/chunks/webpack-*',
273+
'**/page_client-reference-manifest.js',
274+
'**/server-reference-manifest.js',
275+
'**/next-font-manifest.js',
276+
'**/middleware-build-manifest.js',
277+
'**/interception-route-rewrite-manifest.js',
278+
'**/route_client-reference-manifest.js',
279+
'**/middleware-react-loadable-manifest.js',
231280
]);
232281
expect(result.reactComponentAnnotation).toBeUndefined();
233282
});
@@ -444,7 +493,7 @@ describe('getBuildPluginOptions', () => {
444493
expect(result.sourcemaps?.assets).toEqual(customAssets);
445494
});
446495

447-
it('uses custom sourcemap ignore patterns when provided', () => {
496+
it('merges custom sourcemap ignore patterns with defaults', () => {
448497
const customIgnore = ['**/vendor/**', '**/node_modules/**'];
449498
const sentryBuildOptions: SentryBuildOptions = {
450499
org: 'test-org',
@@ -461,7 +510,58 @@ describe('getBuildPluginOptions', () => {
461510
buildTool: 'webpack-client',
462511
});
463512

464-
expect(result.sourcemaps?.ignore).toEqual(customIgnore);
513+
// Custom patterns should be appended to defaults, not replace them
514+
expect(result.sourcemaps?.ignore).toEqual([
515+
'/path/to/.next/static/chunks/main-*',
516+
'/path/to/.next/static/chunks/framework-*',
517+
'/path/to/.next/static/chunks/framework.*',
518+
'/path/to/.next/static/chunks/polyfills-*',
519+
'/path/to/.next/static/chunks/webpack-*',
520+
'**/page_client-reference-manifest.js',
521+
'**/server-reference-manifest.js',
522+
'**/next-font-manifest.js',
523+
'**/middleware-build-manifest.js',
524+
'**/interception-route-rewrite-manifest.js',
525+
'**/route_client-reference-manifest.js',
526+
'**/middleware-react-loadable-manifest.js',
527+
'**/vendor/**',
528+
'**/node_modules/**',
529+
]);
530+
});
531+
532+
it('handles single string custom sourcemap ignore pattern', () => {
533+
const customIgnore = '**/vendor/**';
534+
const sentryBuildOptions: SentryBuildOptions = {
535+
org: 'test-org',
536+
project: 'test-project',
537+
sourcemaps: {
538+
ignore: customIgnore,
539+
},
540+
};
541+
542+
const result = getBuildPluginOptions({
543+
sentryBuildOptions,
544+
releaseName: mockReleaseName,
545+
distDirAbsPath: mockDistDirAbsPath,
546+
buildTool: 'webpack-client',
547+
});
548+
549+
// Single string pattern should be appended to defaults
550+
expect(result.sourcemaps?.ignore).toEqual([
551+
'/path/to/.next/static/chunks/main-*',
552+
'/path/to/.next/static/chunks/framework-*',
553+
'/path/to/.next/static/chunks/framework.*',
554+
'/path/to/.next/static/chunks/polyfills-*',
555+
'/path/to/.next/static/chunks/webpack-*',
556+
'**/page_client-reference-manifest.js',
557+
'**/server-reference-manifest.js',
558+
'**/next-font-manifest.js',
559+
'**/middleware-build-manifest.js',
560+
'**/interception-route-rewrite-manifest.js',
561+
'**/route_client-reference-manifest.js',
562+
'**/middleware-react-loadable-manifest.js',
563+
'**/vendor/**',
564+
]);
465565
});
466566

467567
it('disables sourcemaps when disable flag is set', () => {
@@ -769,6 +869,13 @@ describe('getBuildPluginOptions', () => {
769869
'/path/to/.next/static/chunks/framework.*',
770870
'/path/to/.next/static/chunks/polyfills-*',
771871
'/path/to/.next/static/chunks/webpack-*',
872+
'**/page_client-reference-manifest.js',
873+
'**/server-reference-manifest.js',
874+
'**/next-font-manifest.js',
875+
'**/middleware-build-manifest.js',
876+
'**/interception-route-rewrite-manifest.js',
877+
'**/route_client-reference-manifest.js',
878+
'**/middleware-react-loadable-manifest.js',
772879
],
773880
filesToDeleteAfterUpload: undefined,
774881
rewriteSources: expect.any(Function),

0 commit comments

Comments
 (0)