Skip to content

Commit 69dfc35

Browse files
committed
fix(remix): Rework dynamic imports of react-router-dom.
1 parent ff1229b commit 69dfc35

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/remix/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"peerDependencies": {
4242
"@remix-run/node": "1.x",
4343
"@remix-run/react": "1.x",
44-
"react": "16.x || 17.x || 18.x"
44+
"react": "16.x || 17.x || 18.x",
45+
"react-router": "6.x"
4546
},
4647
"scripts": {
4748
"build": "run-p build:rollup build:types",

packages/remix/rollup.npm.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'
33
export default makeNPMConfigVariants(
44
makeBaseNPMConfig({
55
entrypoints: ['src/index.server.ts', 'src/index.client.tsx'],
6+
packageSpecificConfig: {
7+
output: {
8+
// make it so Rollup calms down about the fact that we're combining default and named exports
9+
exports: 'named',
10+
},
11+
},
612
}),
713
);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ function wrapExpressRequestHandler(
4343
next: ExpressNextFunction,
4444
): Promise<void> {
4545
if (!pkg) {
46-
pkg = await import(`${cwd()}/node_modules/react-router-dom`);
46+
try {
47+
pkg = await import('react-router-dom');
48+
} catch (e) {
49+
pkg = await import(`${cwd()}/node_modules/react-router-dom`);
50+
} finally {
51+
if (!pkg) {
52+
__DEBUG_BUILD__ && logger.error('Could not find `react-router-dom` package.');
53+
}
54+
}
4755
}
4856

4957
// eslint-disable-next-line @typescript-eslint/unbound-method

0 commit comments

Comments
 (0)