File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
packages/nextjs/src/config Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ import { WebpackPluginInstance } from 'webpack';
33
44export type SentryWebpackPluginOptions = SentryCliPluginOptions ;
55export type SentryWebpackPlugin = WebpackPluginInstance & { options : SentryWebpackPluginOptions } ;
6+ // Export this from here because importing something from Webpack (the library) in `webpack.ts` confuses the heck out of
7+ // madge, which we use for circular dependency checking. We've manually excluded this file from the check (which is
8+ // safe, since it only includes types), so we can import it here without causing madge to fail. See
9+ // https://github.com/pahen/madge/issues/306.
10+ export type { WebpackPluginInstance } ;
611
712/**
813 * Overall Nextjs config
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import * as chalk from 'chalk';
66import * as fs from 'fs' ;
77import * as path from 'path' ;
88
9- import {
9+ // Note: If you need to import a type from Webpack, do it in `types.ts` and export it from there. Otherwise, our
10+ // circular dependency check thinks this file is importing from itself. See https://github.com/pahen/madge/issues/306.
11+ import type {
1012 BuildContext ,
1113 EntryPropertyObject ,
1214 NextConfigObject ,
@@ -16,6 +18,7 @@ import {
1618 WebpackConfigObject ,
1719 WebpackEntryProperty ,
1820 WebpackModuleRule ,
21+ WebpackPluginInstance ,
1922} from './types' ;
2023
2124export { SentryWebpackPlugin } ;
@@ -100,6 +103,23 @@ export function constructWebpackConfigFunction(
100103 ] ,
101104 } ) ;
102105 }
106+
107+ // Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from
108+ // including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the
109+ // entirety of rollup and sucrase.)
110+ const nftPlugin = newConfig . plugins ?. find ( ( plugin : WebpackPluginInstance ) => {
111+ const proto = Object . getPrototypeOf ( plugin ) as WebpackPluginInstance ;
112+ return proto . constructor . name === 'TraceEntryPointsPlugin' ;
113+ } ) as WebpackPluginInstance & { excludeFiles : string [ ] } ;
114+ if ( nftPlugin ) {
115+ nftPlugin . excludeFiles = nftPlugin . excludeFiles || [ ] ;
116+ nftPlugin . excludeFiles . push ( path . join ( __dirname , 'withSentryConfig.js' ) ) ;
117+ } else {
118+ __DEBUG_BUILD__ &&
119+ logger . warn (
120+ 'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.' ,
121+ ) ;
122+ }
103123 }
104124
105125 // The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
You can’t perform that action at this time.
0 commit comments