Skip to content

Commit 1f3da81

Browse files
authored
fix(remix): Use import() to get react-router-dom in Express wrapper. (#5796)
`loadModule` utility which we use to acquire `react-router-dom` can return `null` when called from Express wrapper. I suspect the main reason is that we are not monkey-patching Remix core here, like we are doing in the base implementation, the package acquisition is not guaranteed to run when (or where?) `react-router-dom` is available.
1 parent acc9cb1 commit 1f3da81

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
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,
@@ -18,7 +19,6 @@ import {
1819
ExpressRequest,
1920
ExpressRequestHandler,
2021
ExpressResponse,
21-
ReactRouterDomPkg,
2222
ServerBuild,
2323
} from '../types';
2424

@@ -27,7 +27,8 @@ function wrapExpressRequestHandler(
2727
build: ServerBuild,
2828
): ExpressRequestHandler {
2929
const routes = createRoutes(build.routes);
30-
const pkg = loadModule<ReactRouterDomPkg>('react-router-dom');
30+
// eslint-disable-next-line @typescript-eslint/no-var-requires
31+
const pkg = require(`${cwd()}/node_modules/react-router-dom`);
3132

3233
// If the core request handler is already wrapped, don't wrap Express handler which uses it.
3334
if (isRequestHandlerWrapped) {

0 commit comments

Comments
 (0)