@@ -2,7 +2,8 @@ import { getCurrentHub } from '@sentry/hub';
2
2
import { flush } from '@sentry/node' ;
3
3
import { hasTracingEnabled } from '@sentry/tracing' ;
4
4
import { Transaction } from '@sentry/types' ;
5
- import { extractRequestData , isString , loadModule , logger } from '@sentry/utils' ;
5
+ import { extractRequestData , isString , logger } from '@sentry/utils' ;
6
+ import { cwd } from 'process' ;
6
7
7
8
import {
8
9
createRoutes ,
@@ -22,12 +23,13 @@ import {
22
23
ServerBuild ,
23
24
} from '../types' ;
24
25
26
+ let pkg : ReactRouterDomPkg ;
27
+
25
28
function wrapExpressRequestHandler (
26
29
origRequestHandler : ExpressRequestHandler ,
27
30
build : ServerBuild ,
28
31
) : ExpressRequestHandler {
29
32
const routes = createRoutes ( build . routes ) ;
30
- const pkg = loadModule < ReactRouterDomPkg > ( 'react-router-dom' ) ;
31
33
32
34
// If the core request handler is already wrapped, don't wrap Express handler which uses it.
33
35
if ( isRequestHandlerWrapped ) {
@@ -40,6 +42,10 @@ function wrapExpressRequestHandler(
40
42
res : ExpressResponse ,
41
43
next : ExpressNextFunction ,
42
44
) : Promise < void > {
45
+ if ( ! pkg ) {
46
+ pkg = await import ( `${ cwd ( ) } /node_modules/react-router-dom` ) ;
47
+ }
48
+
43
49
// eslint-disable-next-line @typescript-eslint/unbound-method
44
50
res . end = wrapEndMethod ( res . end ) ;
45
51
0 commit comments