From 5e608d2548c83d1bf4de6a4ac1e5f3dff8717e92 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 6 Aug 2021 08:04:30 -0700 Subject: [PATCH 1/2] don't try to upload server/chunks if using webpack 4 --- CHANGELOG.md | 2 ++ packages/nextjs/src/config/types.ts | 1 + packages/nextjs/src/config/webpack.ts | 11 ++++++----- packages/nextjs/test/config.test.ts | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a0fe639467..d03e1b83984a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott +fix(nextjs): Differentiate between webpack 4 and 5 in server builds (#FIXME!!) + ## 6.11.0 feat(nextjs): Allow for TypeScript user config files (#3847) diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 0a4adb8dad1c..b577268f41cb 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -54,6 +54,7 @@ export type BuildContext = { buildId: string; dir: string; config: Partial; + webpack: { version: string }; }; /** diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 643b17623d39..a4807dccc53b 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -242,17 +242,18 @@ function getWebpackPluginOptions( buildContext: BuildContext, userPluginOptions: Partial, ): SentryWebpackPluginOptions { - const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig } = buildContext; + const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig, webpack } = buildContext; + const isWebpack5 = webpack.version.startsWith('5'); const isServerless = nextConfig.target === 'experimental-serverless-trace'; const hasSentryProperties = fs.existsSync(path.resolve(projectDir, 'sentry.properties')); const serverInclude = isServerless ? [{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' }] - : [ - { paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }, - { paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }, - ]; + : [{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }].concat( + isWebpack5 ? [{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }] : [], + ); + const clientInclude = [{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' }]; const defaultPluginOptions = dropUndefinedKeys({ diff --git a/packages/nextjs/test/config.test.ts b/packages/nextjs/test/config.test.ts index 636266cd404b..ad26cb27eab6 100644 --- a/packages/nextjs/test/config.test.ts +++ b/packages/nextjs/test/config.test.ts @@ -89,6 +89,7 @@ const baseBuildContext = { buildId: 'sItStAyLiEdOwN', dir: '/Users/Maisey/projects/squirrelChasingSimulator', config: { target: 'server' as const }, + webpack: { version: '5.4.15' }, }; const serverBuildContext = { isServer: true, ...baseBuildContext }; const clientBuildContext = { isServer: false, ...baseBuildContext }; @@ -389,7 +390,21 @@ describe('Sentry webpack plugin config', () => { ]); }); - it('has the correct value when building serverful server bundles', async () => { + it('has the correct value when building serverful server bundles using webpack 4', async () => { + const finalWebpackConfig = await materializeFinalWebpackConfig({ + userNextConfig, + incomingWebpackConfig: serverWebpackConfig, + incomingWebpackBuildContext: { ...serverBuildContext, webpack: { version: '4' } }, + }); + + const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType; + + expect(sentryWebpackPlugin.options?.include).toEqual([ + { paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }, + ]); + }); + + it('has the correct value when building serverful server bundles using webpack 5', async () => { const finalWebpackConfig = await materializeFinalWebpackConfig({ userNextConfig, incomingWebpackConfig: serverWebpackConfig, @@ -399,8 +414,8 @@ describe('Sentry webpack plugin config', () => { const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType; expect(sentryWebpackPlugin.options?.include).toEqual([ - { paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }, { paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }, + { paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }, ]); }); }); From f3d187d0299955632c98e6b67aed098ed531e3aa Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 17 Aug 2021 20:12:38 -0700 Subject: [PATCH 2/2] use full semver version for test --- packages/nextjs/test/config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/test/config.test.ts b/packages/nextjs/test/config.test.ts index ad26cb27eab6..29e575452ed6 100644 --- a/packages/nextjs/test/config.test.ts +++ b/packages/nextjs/test/config.test.ts @@ -394,7 +394,7 @@ describe('Sentry webpack plugin config', () => { const finalWebpackConfig = await materializeFinalWebpackConfig({ userNextConfig, incomingWebpackConfig: serverWebpackConfig, - incomingWebpackBuildContext: { ...serverBuildContext, webpack: { version: '4' } }, + incomingWebpackBuildContext: { ...serverBuildContext, webpack: { version: '4.15.13' } }, }); const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;