Skip to content

Commit 85c2df4

Browse files
committed
normalize paths for webpack
1 parent 6e9972e commit 85c2df4

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

packages/nextjs/src/config/getBuildPluginOptions.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ export function getBuildPluginOptions({
7070
if (buildTool === 'webpack-nodejs' || buildTool === 'webpack-edge') {
7171
// Webpack server builds
7272
sourcemapUploadAssets.push(
73-
path.posix.join(distDirAbsPath, 'server', '**'), // Standard output location for server builds
74-
path.posix.join(distDirAbsPath, 'serverless', '**'), // Legacy output location for serverless Next.js
73+
path.posix.join(normalizedDistDirAbsPath, 'server', '**'), // Standard output location for server builds
74+
path.posix.join(normalizedDistDirAbsPath, 'serverless', '**'), // Legacy output location for serverless Next.js
7575
);
7676
} else {
7777
// Webpack client builds
7878
if (sentryBuildOptions.widenClientFileUpload) {
79-
sourcemapUploadAssets.push(path.posix.join(distDirAbsPath, 'static', 'chunks', '**'));
79+
sourcemapUploadAssets.push(path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', '**'));
8080
} else {
8181
sourcemapUploadAssets.push(
82-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'pages', '**'),
83-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'app', '**'),
82+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'pages', '**'),
83+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'app', '**'),
8484
);
8585
}
8686

@@ -91,25 +91,25 @@ export function getBuildPluginOptions({
9191
// We only care to delete client bundle source maps because they would be the ones being served.
9292
// Removing the server source maps crashes Vercel builds for (thus far) unknown reasons:
9393
// https://github.com/getsentry/sentry-javascript/issues/13099
94-
path.posix.join(distDirAbsPath, 'static', '**', '*.js.map'),
95-
path.posix.join(distDirAbsPath, 'static', '**', '*.mjs.map'),
96-
path.posix.join(distDirAbsPath, 'static', '**', '*.cjs.map'),
94+
path.posix.join(normalizedDistDirAbsPath, 'static', '**', '*.js.map'),
95+
path.posix.join(normalizedDistDirAbsPath, 'static', '**', '*.mjs.map'),
96+
path.posix.join(normalizedDistDirAbsPath, 'static', '**', '*.cjs.map'),
9797
);
9898
}
9999
}
100100
}
101101

102102
// We want to include main-* files if widenClientFileUpload is true as they have proven to be useful
103103
if (!sentryBuildOptions.widenClientFileUpload) {
104-
sourcemapUploadIgnore.push(path.posix.join(distDirAbsPath, 'static', 'chunks', 'main-*'));
104+
sourcemapUploadIgnore.push(path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'main-*'));
105105
}
106106

107107
// Always ignore framework, polyfills, and webpack files
108108
sourcemapUploadIgnore.push(
109-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'framework-*'),
110-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'framework.*'),
111-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'polyfills-*'),
112-
path.posix.join(distDirAbsPath, 'static', 'chunks', 'webpack-*'),
109+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'framework-*'),
110+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'framework.*'),
111+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'polyfills-*'),
112+
path.posix.join(normalizedDistDirAbsPath, 'static', 'chunks', 'webpack-*'),
113113
);
114114

115115
// If the user has opted into using the experimental hook, we skip sourcemap uploads in the plugin

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('getBuildPluginOptions', () => {
8181
]);
8282
});
8383

84-
it('does not normalize paths for webpack builds', () => {
84+
it('normalizes Windows paths to posix for webpack builds', () => {
8585
const windowsPath = 'C:\\Users\\test\\.next';
8686
const sentryBuildOptions: SentryBuildOptions = {
8787
org: 'test-org',
@@ -95,10 +95,9 @@ describe('getBuildPluginOptions', () => {
9595
buildTool: 'webpack-client',
9696
});
9797

98-
// Webpack builds should use the original path without normalization
9998
expect(result.sourcemaps?.assets).toEqual([
100-
'C:\\Users\\test\\.next/static/chunks/pages/**',
101-
'C:\\Users\\test\\.next/static/chunks/app/**',
99+
'C:/Users/test/.next/static/chunks/pages/**',
100+
'C:/Users/test/.next/static/chunks/app/**',
102101
]);
103102
});
104103
});

0 commit comments

Comments
 (0)