@@ -6,7 +6,9 @@ import * as chalk from 'chalk';
6
6
import * as fs from 'fs' ;
7
7
import * as path from 'path' ;
8
8
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 {
10
12
BuildContext ,
11
13
EntryPropertyObject ,
12
14
NextConfigObject ,
@@ -16,6 +18,7 @@ import {
16
18
WebpackConfigObject ,
17
19
WebpackEntryProperty ,
18
20
WebpackModuleRule ,
21
+ WebpackPluginInstance ,
19
22
} from './types' ;
20
23
21
24
export { SentryWebpackPlugin } ;
@@ -100,6 +103,30 @@ export function constructWebpackConfigFunction(
100
103
] ,
101
104
} ) ;
102
105
}
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
+ if ( Array . isArray ( 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. `TraceEntryPointsPlugin.excludeFiles` is not ' +
121
+ 'an array. This is a bug; please report this to Sentry: https://github.com/getsentry/sentry-javascript/issues/.' ,
122
+ ) ;
123
+ }
124
+ } else {
125
+ __DEBUG_BUILD__ &&
126
+ logger . warn (
127
+ 'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.' ,
128
+ ) ;
129
+ }
103
130
}
104
131
105
132
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
0 commit comments