@@ -2,7 +2,8 @@ import { getCurrentHub } from '@sentry/hub';
22import { flush } from '@sentry/node' ;
33import { hasTracingEnabled } from '@sentry/tracing' ;
44import { 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' ;
67
78import {
89 createRoutes ,
@@ -22,12 +23,13 @@ import {
2223 ServerBuild ,
2324} from '../types' ;
2425
26+ let pkg : ReactRouterDomPkg ;
27+
2528function wrapExpressRequestHandler (
2629 origRequestHandler : ExpressRequestHandler ,
2730 build : ServerBuild ,
2831) : ExpressRequestHandler {
2932 const routes = createRoutes ( build . routes ) ;
30- const pkg = loadModule < ReactRouterDomPkg > ( 'react-router-dom' ) ;
3133
3234 // If the core request handler is already wrapped, don't wrap Express handler which uses it.
3335 if ( isRequestHandlerWrapped ) {
@@ -40,6 +42,10 @@ function wrapExpressRequestHandler(
4042 res : ExpressResponse ,
4143 next : ExpressNextFunction ,
4244 ) : Promise < void > {
45+ if ( ! pkg ) {
46+ pkg = await import ( `${ cwd ( ) } /node_modules/react-router-dom` ) ;
47+ }
48+
4349 // eslint-disable-next-line @typescript-eslint/unbound-method
4450 res . end = wrapEndMethod ( res . end ) ;
4551
0 commit comments