Skip to content

Commit 251893b

Browse files
authored
chore: set resolve.mainFields and resolve.conditions for SSR environment (#6896)
1 parent 76169a1 commit 251893b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/vitest/src/node/plugins/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ export async function VitestPlugin(
113113
// https://github.com/vitejs/vite/pull/16453
114114
emptyOutDir: false,
115115
},
116+
// eslint-disable-next-line ts/ban-ts-comment
117+
// @ts-ignore Vite 6 compat
118+
environments: {
119+
ssr: {
120+
resolve: {
121+
// by default Vite resolves `module` field, which not always a native ESM module
122+
// setting this option can bypass that and fallback to cjs version
123+
mainFields: [],
124+
conditions: ['node'],
125+
},
126+
},
127+
},
116128
test: {
117129
poolOptions: {
118130
threads: {

packages/vitest/src/node/plugins/workspace.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ export function WorkspaceVitestPlugin(
9696
),
9797
},
9898
},
99+
// eslint-disable-next-line ts/ban-ts-comment
100+
// @ts-ignore Vite 6 compat
101+
environments: {
102+
ssr: {
103+
resolve: {
104+
// by default Vite resolves `module` field, which not always a native ESM module
105+
// setting this option can bypass that and fallback to cjs version
106+
mainFields: [],
107+
conditions: ['node'],
108+
},
109+
},
110+
},
99111
test: {
100112
name,
101113
},

0 commit comments

Comments
 (0)