From a85519ad9514df685b6c311adc6ca04ce9cd0cbc Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 25 Oct 2022 10:34:48 -0700 Subject: [PATCH] exclude build-time files --- packages/nextjs/src/config/webpack.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 0574b4af03c0..fd2377609f6e 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -105,6 +105,22 @@ export function constructWebpackConfigFunction( ], }); } + + // Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from + // including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the + // entirety of rollup and sucrase.) + const nftPlugin = newConfig.plugins?.find((plugin: WebpackPluginInstance) => { + const proto = Object.getPrototypeOf(plugin) as WebpackPluginInstance; + return proto.constructor.name === 'TraceEntryPointsPlugin'; + }) as NFTWebpackPlugin; + if (nftPlugin) { + nftPlugin.excludeFiles.push(path.join(__dirname, 'index.js')); + } else { + __DEBUG_BUILD__ && + logger.warn( + 'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.', + ); + } } // The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users