diff --git a/.changeset/lemon-buckets-matter.md b/.changeset/lemon-buckets-matter.md new file mode 100644 index 0000000000..9aa52eab6c --- /dev/null +++ b/.changeset/lemon-buckets-matter.md @@ -0,0 +1,5 @@ +--- +"@react-router/dev": patch +--- + +Don't use `"module"` server conditions in Vitest diff --git a/contributors.yml b/contributors.yml index e08e21fce8..998e67143d 100644 --- a/contributors.yml +++ b/contributors.yml @@ -415,3 +415,4 @@ - zeromask1337 - zheng-chuang - zxTomw +- remorses diff --git a/packages/react-router-dev/vite/plugin.ts b/packages/react-router-dev/vite/plugin.ts index 2a485e5b1b..3d6ed80ffb 100644 --- a/packages/react-router-dev/vite/plugin.ts +++ b/packages/react-router-dev/vite/plugin.ts @@ -3470,6 +3470,7 @@ export async function getEnvironmentOptionsResolvers( ); let vite = getVite(); + function getBaseOptions({ viteUserConfig, }: { @@ -3544,6 +3545,14 @@ export async function getEnvironmentOptionsResolvers( // https://vite.dev/guide/migration.html#default-value-for-resolve-conditions let maybeDefaultServerConditions = vite.defaultServerConditions || []; + + if (process.env.VITEST) { + // Vitest will fail to import packages that distribute invalid ESM if the condition "module" is added: https://github.com/remix-run/react-router/issues/13869 + maybeDefaultServerConditions = maybeDefaultServerConditions.filter( + (condition) => condition !== "module" + ); + } + // There is no helpful export with the default external conditions (see // https://github.com/vitejs/vite/pull/20279 for more details). So, for now, // we are hardcording the default here.