@@ -3,7 +3,6 @@ import { getSentryRelease } from '@sentry/node';
3
3
import { dropUndefinedKeys , logger } from '@sentry/utils' ;
4
4
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin' ;
5
5
import * as fs from 'fs' ;
6
- import * as os from 'os' ;
7
6
import * as path from 'path' ;
8
7
9
8
import {
@@ -51,6 +50,29 @@ export function constructWebpackConfigFunction(
51
50
newConfig = userNextConfig . webpack ( newConfig , buildContext ) ;
52
51
}
53
52
53
+ if ( isServer ) {
54
+ newConfig . module = {
55
+ ...newConfig . module ,
56
+ rules : [
57
+ ...( newConfig . module ?. rules || [ ] ) ,
58
+ {
59
+ test : / s e n t r y \. s e r v e r \. c o n f i g \. ( j s x ? | t s x ? ) / ,
60
+ use : [
61
+ {
62
+ // Support non-default output directories by making the output path (easy to get here at build-time)
63
+ // available to the server SDK's default `RewriteFrames` instance (which needs it at runtime), by
64
+ // injecting code to attach it to `global`.
65
+ loader : path . resolve ( __dirname , 'prefixLoader.js' ) ,
66
+ options : {
67
+ distDir : userNextConfig . distDir || '.next' ,
68
+ } ,
69
+ } ,
70
+ ] ,
71
+ } ,
72
+ ] ,
73
+ } ;
74
+ }
75
+
54
76
// Tell webpack to inject user config files (containing the two `Sentry.init()` calls) into the appropriate output
55
77
// bundles. Store a separate reference to the original `entry` value to avoid an infinite loop. (If we don't do
56
78
// this, we'll have a statement of the form `x.y = () => f(x.y)`, where one of the things `f` does is call `x.y`.
@@ -121,7 +143,7 @@ async function addSentryToEntryProperty(
121
143
// we know is that it won't have gotten *simpler* in form, so we only need to worry about the object and function
122
144
// options. See https://webpack.js.org/configuration/entry-context/#entry.
123
145
124
- const { isServer, dir : projectDir , dev : isDev , config : userNextConfig } = buildContext ;
146
+ const { isServer, dir : projectDir } = buildContext ;
125
147
126
148
const newEntryProperty =
127
149
typeof currentEntryProperty === 'function' ? await currentEntryProperty ( ) : { ...currentEntryProperty } ;
@@ -132,21 +154,6 @@ async function addSentryToEntryProperty(
132
154
// we need to turn the filename into a path so webpack can find it
133
155
const filesToInject = [ `./${ userConfigFile } ` ] ;
134
156
135
- // Support non-default output directories by making the output path (easy to get here at build-time) available to the
136
- // server SDK's default `RewriteFrames` instance (which needs it at runtime). Doesn't work when using the dev server
137
- // because it somehow tricks the file watcher into thinking that compilation itself is a file change, triggering an
138
- // infinite recompiling loop. (This should be fine because we don't upload sourcemaps in dev in any case.)
139
- if ( isServer && ! isDev ) {
140
- const rewriteFramesHelper = path . resolve (
141
- fs . mkdtempSync ( path . resolve ( os . tmpdir ( ) , 'sentry-' ) ) ,
142
- 'rewriteFramesHelper.js' ,
143
- ) ;
144
- fs . writeFileSync ( rewriteFramesHelper , `global.__rewriteFramesDistDir__ = '${ userNextConfig . distDir } ';\n` ) ;
145
- // stick our helper file ahead of the user's config file so the value is in the global namespace *before*
146
- // `Sentry.init()` is called
147
- filesToInject . unshift ( rewriteFramesHelper ) ;
148
- }
149
-
150
157
// inject into all entry points which might contain user's code
151
158
for ( const entryPointName in newEntryProperty ) {
152
159
if ( shouldAddSentryToEntryPoint ( entryPointName , isServer ) ) {
0 commit comments