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';
3
3
4
4
export type SentryWebpackPluginOptions = SentryCliPluginOptions ;
5
5
export 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 } ;
6
11
7
12
/**
8
13
* Overall Nextjs config
Original file line number Diff line number Diff line change @@ -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,23 @@ 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
+ 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
+ }
103
123
}
104
124
105
125
// 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