From 251893b41caaff26b9c3fb59cb79216bec9d149f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 13 Nov 2024 19:54:04 +0900 Subject: [PATCH] chore: set `resolve.mainFields` and `resolve.conditions` for SSR environment (#6896) --- packages/vitest/src/node/plugins/index.ts | 12 ++++++++++++ packages/vitest/src/node/plugins/workspace.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index 5b687e27e421..b24a0e06fce8 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -113,6 +113,18 @@ export async function VitestPlugin( // https://github.com/vitejs/vite/pull/16453 emptyOutDir: false, }, + // eslint-disable-next-line ts/ban-ts-comment + // @ts-ignore Vite 6 compat + environments: { + ssr: { + resolve: { + // by default Vite resolves `module` field, which not always a native ESM module + // setting this option can bypass that and fallback to cjs version + mainFields: [], + conditions: ['node'], + }, + }, + }, test: { poolOptions: { threads: { diff --git a/packages/vitest/src/node/plugins/workspace.ts b/packages/vitest/src/node/plugins/workspace.ts index bdffdbe16117..8f4e3c9027e0 100644 --- a/packages/vitest/src/node/plugins/workspace.ts +++ b/packages/vitest/src/node/plugins/workspace.ts @@ -96,6 +96,18 @@ export function WorkspaceVitestPlugin( ), }, }, + // eslint-disable-next-line ts/ban-ts-comment + // @ts-ignore Vite 6 compat + environments: { + ssr: { + resolve: { + // by default Vite resolves `module` field, which not always a native ESM module + // setting this option can bypass that and fallback to cjs version + mainFields: [], + conditions: ['node'], + }, + }, + }, test: { name, },