Skip to content

Commit 5e608d2

Browse files
committed
don't try to upload server/chunks if using webpack 4
1 parent a27c0fa commit 5e608d2

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
fix(nextjs): Differentiate between webpack 4 and 5 in server builds (#FIXME!!)
8+
79
## 6.11.0
810

911
feat(nextjs): Allow for TypeScript user config files (#3847)

packages/nextjs/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type BuildContext = {
5454
buildId: string;
5555
dir: string;
5656
config: Partial<NextConfigObject>;
57+
webpack: { version: string };
5758
};
5859

5960
/**

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,18 @@ function getWebpackPluginOptions(
242242
buildContext: BuildContext,
243243
userPluginOptions: Partial<SentryWebpackPluginOptions>,
244244
): SentryWebpackPluginOptions {
245-
const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig } = buildContext;
245+
const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig, webpack } = buildContext;
246246

247+
const isWebpack5 = webpack.version.startsWith('5');
247248
const isServerless = nextConfig.target === 'experimental-serverless-trace';
248249
const hasSentryProperties = fs.existsSync(path.resolve(projectDir, 'sentry.properties'));
249250

250251
const serverInclude = isServerless
251252
? [{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' }]
252-
: [
253-
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
254-
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
255-
];
253+
: [{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }].concat(
254+
isWebpack5 ? [{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }] : [],
255+
);
256+
256257
const clientInclude = [{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' }];
257258

258259
const defaultPluginOptions = dropUndefinedKeys({

packages/nextjs/test/config.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const baseBuildContext = {
8989
buildId: 'sItStAyLiEdOwN',
9090
dir: '/Users/Maisey/projects/squirrelChasingSimulator',
9191
config: { target: 'server' as const },
92+
webpack: { version: '5.4.15' },
9293
};
9394
const serverBuildContext = { isServer: true, ...baseBuildContext };
9495
const clientBuildContext = { isServer: false, ...baseBuildContext };
@@ -389,7 +390,21 @@ describe('Sentry webpack plugin config', () => {
389390
]);
390391
});
391392

392-
it('has the correct value when building serverful server bundles', async () => {
393+
it('has the correct value when building serverful server bundles using webpack 4', async () => {
394+
const finalWebpackConfig = await materializeFinalWebpackConfig({
395+
userNextConfig,
396+
incomingWebpackConfig: serverWebpackConfig,
397+
incomingWebpackBuildContext: { ...serverBuildContext, webpack: { version: '4' } },
398+
});
399+
400+
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
401+
402+
expect(sentryWebpackPlugin.options?.include).toEqual([
403+
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
404+
]);
405+
});
406+
407+
it('has the correct value when building serverful server bundles using webpack 5', async () => {
393408
const finalWebpackConfig = await materializeFinalWebpackConfig({
394409
userNextConfig,
395410
incomingWebpackConfig: serverWebpackConfig,
@@ -399,8 +414,8 @@ describe('Sentry webpack plugin config', () => {
399414
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
400415

401416
expect(sentryWebpackPlugin.options?.include).toEqual([
402-
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
403417
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
418+
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
404419
]);
405420
});
406421
});

0 commit comments

Comments
 (0)