Skip to content

Commit a9e78b7

Browse files
authored
fix(remix): Use import() to get react-router-dom in Express wrapper. (#5810)
1 parent ddc0481 commit a9e78b7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/remix/src/utils/serverAdapters/express.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { getCurrentHub } from '@sentry/hub';
22
import { flush } from '@sentry/node';
33
import { hasTracingEnabled } from '@sentry/tracing';
44
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';
67

78
import {
89
createRoutes,
@@ -22,12 +23,13 @@ import {
2223
ServerBuild,
2324
} from '../types';
2425

26+
let pkg: ReactRouterDomPkg;
27+
2528
function 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

Comments
 (0)