From 48691e24733a21b53e67877b7fa26f781ed3e417 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 7 Nov 2025 11:11:51 +0100 Subject: [PATCH] fix(nextjs): Ensure sourcemaps upload ignore patterns are relative Closes: #18108 --- .../src/config/getBuildPluginOptions.ts | 18 ++-- .../test/config/getBuildPluginOptions.test.ts | 85 ++++++++++--------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/packages/nextjs/src/config/getBuildPluginOptions.ts b/packages/nextjs/src/config/getBuildPluginOptions.ts index 6de802917015..396b5bbe22da 100644 --- a/packages/nextjs/src/config/getBuildPluginOptions.ts +++ b/packages/nextjs/src/config/getBuildPluginOptions.ts @@ -124,24 +124,22 @@ function createSourcemapUploadAssetPatterns( /** * Creates ignore patterns for source map uploads + * Note: These patterns are relative to the upload path, not absolute paths */ -function createSourcemapUploadIgnorePattern( - normalizedDistPath: string, - widenClientFileUpload: boolean = false, -): string[] { +function createSourcemapUploadIgnorePattern(widenClientFileUpload: boolean = false): string[] { const ignore: string[] = []; // We only add main-* files if the user has not opted into it if (!widenClientFileUpload) { - ignore.push(path.posix.join(normalizedDistPath, FILE_PATTERNS.MAIN_CHUNKS)); + ignore.push(FILE_PATTERNS.MAIN_CHUNKS); } // Always ignore these patterns ignore.push( - path.posix.join(normalizedDistPath, FILE_PATTERNS.FRAMEWORK_CHUNKS), - path.posix.join(normalizedDistPath, FILE_PATTERNS.FRAMEWORK_CHUNKS_DOT), - path.posix.join(normalizedDistPath, FILE_PATTERNS.POLYFILLS_CHUNKS), - path.posix.join(normalizedDistPath, FILE_PATTERNS.WEBPACK_CHUNKS), + FILE_PATTERNS.FRAMEWORK_CHUNKS, + FILE_PATTERNS.FRAMEWORK_CHUNKS_DOT, + FILE_PATTERNS.POLYFILLS_CHUNKS, + FILE_PATTERNS.WEBPACK_CHUNKS, ); return ignore; @@ -250,7 +248,7 @@ export function getBuildPluginOptions({ widenClientFileUpload, ); - const sourcemapUploadIgnore = createSourcemapUploadIgnorePattern(normalizedDistDirAbsPath, widenClientFileUpload); + const sourcemapUploadIgnore = createSourcemapUploadIgnorePattern(widenClientFileUpload); const filesToDeleteAfterUpload = createFilesToDeleteAfterUploadPattern( normalizedDistDirAbsPath, diff --git a/packages/nextjs/test/config/getBuildPluginOptions.test.ts b/packages/nextjs/test/config/getBuildPluginOptions.test.ts index 0281624584d0..00d03e9b3c32 100644 --- a/packages/nextjs/test/config/getBuildPluginOptions.test.ts +++ b/packages/nextjs/test/config/getBuildPluginOptions.test.ts @@ -28,11 +28,11 @@ describe('getBuildPluginOptions', () => { sourcemaps: { assets: ['/path/to/.next/server', '/path/to/.next/static/chunks/pages', '/path/to/.next/static/chunks/app'], ignore: [ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ], filesToDeleteAfterUpload: undefined, rewriteSources: expect.any(Function), @@ -93,6 +93,13 @@ describe('getBuildPluginOptions', () => { 'C:/Users/test/.next/static/chunks/pages/**', 'C:/Users/test/.next/static/chunks/app/**', ]); + expect(result.sourcemaps?.ignore).toEqual([ + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', + ]); }); }); @@ -116,11 +123,11 @@ describe('getBuildPluginOptions', () => { '/path/to/.next/static/chunks/app/**', ]); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); expect(result.reactComponentAnnotation).toBeDefined(); }); @@ -138,10 +145,10 @@ describe('getBuildPluginOptions', () => { expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/static/chunks/**']); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); }); @@ -156,11 +163,11 @@ describe('getBuildPluginOptions', () => { expect(result._metaOptions?.loggerPrefixOverride).toBe('[@sentry/nextjs - Node.js]'); expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/server/**', '/path/to/.next/serverless/**']); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); expect(result.reactComponentAnnotation).toBeDefined(); }); @@ -176,11 +183,11 @@ describe('getBuildPluginOptions', () => { expect(result._metaOptions?.loggerPrefixOverride).toBe('[@sentry/nextjs - Edge]'); expect(result.sourcemaps?.assets).toEqual(['/path/to/.next/server/**', '/path/to/.next/serverless/**']); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); expect(result.reactComponentAnnotation).toBeDefined(); }); @@ -200,11 +207,11 @@ describe('getBuildPluginOptions', () => { '/path/to/.next/static/chunks/app', ]); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); expect(result.reactComponentAnnotation).toBeUndefined(); }); @@ -223,11 +230,11 @@ describe('getBuildPluginOptions', () => { '/path/to/.next/static/chunks', // Turbopack uses broader pattern ]); expect(result.sourcemaps?.ignore).toEqual([ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ]); expect(result.reactComponentAnnotation).toBeUndefined(); }); @@ -755,11 +762,11 @@ describe('getBuildPluginOptions', () => { disable: false, assets: ['/path/to/.next/server', '/path/to/.next/static/chunks/pages', '/path/to/.next/static/chunks/app'], ignore: [ - '/path/to/.next/static/chunks/main-*', - '/path/to/.next/static/chunks/framework-*', - '/path/to/.next/static/chunks/framework.*', - '/path/to/.next/static/chunks/polyfills-*', - '/path/to/.next/static/chunks/webpack-*', + 'static/chunks/main-*', + 'static/chunks/framework-*', + 'static/chunks/framework.*', + 'static/chunks/polyfills-*', + 'static/chunks/webpack-*', ], filesToDeleteAfterUpload: undefined, rewriteSources: expect.any(Function),