From 69dfc3516896a60245ad616f33e4517902202581 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Thu, 6 Oct 2022 10:40:01 +0100 Subject: [PATCH 1/2] fix(remix): Rework dynamic imports of `react-router-dom`. --- packages/remix/package.json | 3 ++- packages/remix/rollup.npm.config.js | 6 ++++++ packages/remix/src/utils/serverAdapters/express.ts | 10 +++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/remix/package.json b/packages/remix/package.json index 7151bfaa06af..109215873186 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -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", diff --git a/packages/remix/rollup.npm.config.js b/packages/remix/rollup.npm.config.js index 4689937a652c..164789dc84b9 100644 --- a/packages/remix/rollup.npm.config.js +++ b/packages/remix/rollup.npm.config.js @@ -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', + }, + }, }), ); diff --git a/packages/remix/src/utils/serverAdapters/express.ts b/packages/remix/src/utils/serverAdapters/express.ts index 76ef655236ff..1a4944c43aac 100644 --- a/packages/remix/src/utils/serverAdapters/express.ts +++ b/packages/remix/src/utils/serverAdapters/express.ts @@ -43,7 +43,15 @@ function wrapExpressRequestHandler( next: ExpressNextFunction, ): Promise { 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 From d4b21ef92b12bc9cab830c31f609bea0cca272f8 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Thu, 6 Oct 2022 11:22:17 +0100 Subject: [PATCH 2/2] Flag `react-router` as `external` without making it a peer dep. --- packages/remix/package.json | 3 +-- packages/remix/rollup.npm.config.js | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/remix/package.json b/packages/remix/package.json index 109215873186..7151bfaa06af 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -41,8 +41,7 @@ "peerDependencies": { "@remix-run/node": "1.x", "@remix-run/react": "1.x", - "react": "16.x || 17.x || 18.x", - "react-router": "6.x" + "react": "16.x || 17.x || 18.x" }, "scripts": { "build": "run-p build:rollup build:types", diff --git a/packages/remix/rollup.npm.config.js b/packages/remix/rollup.npm.config.js index 164789dc84b9..dc51f24c7bb2 100644 --- a/packages/remix/rollup.npm.config.js +++ b/packages/remix/rollup.npm.config.js @@ -4,6 +4,7 @@ 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',