8000 fix(remix): Rework dynamic imports of `react-router-dom` (#5897) · philipatkinson/sentry-javascript@e406130 · GitHub
[go: up one dir, main page]

Skip to content

Commit e406130

Browse files
authored
fix(remix): Rework dynamic imports of react-router-dom (getsentry#5897)
Added import by name as the first priority (which will work in monorepos) and relative imports as the second if the former fails. Logging error at the end if the latter fails too, without breaking the whole application. This implementation is similar to the loadModule implementation below, only the priorities are swapped. (The other way works too).
1 parent 1d5c610 commit e406130

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/remix/rollup.npm.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@ 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+
external: ['react-router', 'react-router-dom'],
8+
output: {
9+
// make it so Rollup calms down about the fact that we're combining default and named exports
10+
exports: 'named',
11+
},
12+
},
613
}),
714
);

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)
0