Skip to content

Commit

Permalink
fix(remix): Rework dynamic imports of react-router-dom.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Oct 6, 2022
1 parent ff1229b commit 69dfc35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/remix/package.json
Expand Up @@ -41,7 +41,8 @@
"peerDependencies": {
"@remix-run/node": "1.x",
"@remix-run/react": "1.x",
"react": "16.x || 17.x || 18.x"
"react": "16.x || 17.x || 18.x",
"react-router": "6.x"
},
"scripts": {
"build": "run-p build:rollup build:types",
Expand Down
6 changes: 6 additions & 0 deletions packages/remix/rollup.npm.config.js
Expand Up @@ -3,5 +3,11 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'
export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.server.ts', 'src/index.client.tsx'],
packageSpecificConfig: {
output: {
// make it so Rollup calms down about the fact that we're combining default and named exports
exports: 'named',
},
},
}),
);
10 changes: 9 additions & 1 deletion packages/remix/src/utils/serverAdapters/express.ts
Expand Up @@ -43,7 +43,15 @@ function wrapExpressRequestHandler(
next: ExpressNextFunction,
): Promise<void> {
if (!pkg) {
pkg = await import(`${cwd()}/node_modules/react-router-dom`);
try {
pkg = await import('react-router-dom');
} catch (e) {
pkg = await import(`${cwd()}/node_modules/react-router-dom`);
} finally {
if (!pkg) {
__DEBUG_BUILD__ && logger.error('Could not find `react-router-dom` package.');
}
}
}

// eslint-disable-next-line @typescript-eslint/unbound-method
Expand Down

0 comments on commit 69dfc35

Please sign in to comment.