Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(remix): Rework dynamic imports of react-router-dom. #5897

Merged
merged 2 commits into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/remix/rollup.npm.config.js
Expand Up @@ -3,5 +3,12 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'
export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.server.ts', 'src/index.client.tsx'],
packageSpecificConfig: {
external: ['react-router', 'react-router-dom'],
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