···129129130130See PR for more details: [#5876](https://github.com/vitest-dev/vitest/pull/5876).
131131132132+### `module` condition export is not resolved by default on Vite 6
133133+134134+Vite 6 allows more flexible [`resolve.conditions`](https://vite.dev/config/shared-options#resolve-conditions) options and Vitest configures it to exclude `module` conditional export by default.
135135+132136### `Custom` Type is Deprecated <Badge type="danger">API</Badge> {#custom-type-is-deprecated}
133137134138The `Custom` type is now an alias for the `Test` type. Note that Vitest updated the public types in 2.1 and changed exported names to `RunnerCustomCase` and `RunnerTestCase`:
···2020import { SsrReplacerPlugin } from './ssrReplacer'
2121import {
2222 deleteDefineConfig,
2323+ getDefaultResolveOptions,
2324 hijackVitePluginInject,
2425 resolveFsAllow,
2526} from './utils'
···7374 open = testConfig.uiBase ?? '/__vitest__/'
7475 }
75767777+ const resolveOptions = getDefaultResolveOptions()
7878+7679 const config: ViteConfig = {
7780 root: viteConfig.test?.root || options.root,
7881 esbuild:
···8689 legalComments: 'inline',
8790 },
8891 resolve: {
8989- // by default Vite resolves `module` field, which not always a native ESM module
9090- // setting this option can bypass that and fallback to cjs version
9191- mainFields: [],
9292+ ...resolveOptions,
9293 alias: testConfig.alias,
9393- conditions: ['node'],
9494 },
9595 server: {
9696 ...testConfig.api,
···115115 // @ts-ignore Vite 6 compat
116116 environments: {
117117 ssr: {
118118- resolve: {
119119- // by default Vite resolves `module` field, which not always a native ESM module
120120- // setting this option can bypass that and fallback to cjs version
121121- mainFields: [],
122122- conditions: ['node'],
123123- },
118118+ resolve: resolveOptions,
124119 },
125120 },
126121 test: {
+21
packages/vitest/src/node/plugins/utils.ts
···66import type { DepsOptimizationOptions, InlineConfig } from '../types/config'
77import { dirname } from 'pathe'
88import { searchForWorkspaceRoot, version as viteVersion } from 'vite'
99+import * as vite from 'vite'
910import { rootDir } from '../../paths'
1011import { VitestCache } from '../cache'
1112···146147 searchForWorkspaceRoot(projectRoot),
147148 rootDir,
148149 ]
150150+}
151151+152152+export function getDefaultResolveOptions(): vite.ResolveOptions {
153153+ return {
154154+ // by default Vite resolves `module` field, which is not always a native ESM module
155155+ // setting this option can bypass that and fallback to cjs version
156156+ mainFields: [],
157157+ // same for `module` condition and Vite 5 doesn't even allow excluding it,
158158+ // but now it's possible since Vite 6.
159159+ conditions: getDefaultServerConditions(),
160160+ }
161161+}
162162+163163+function getDefaultServerConditions(): string[] {
164164+ const viteMajor = Number(viteVersion.split('.')[0])
165165+ if (viteMajor >= 6) {
166166+ const conditions: string[] = (vite as any).defaultServerConditions
167167+ return conditions.filter(c => c !== 'module')
168168+ }
169169+ return ['node']
149170}
+4-10
packages/vitest/src/node/plugins/workspace.ts
···1616import { SsrReplacerPlugin } from './ssrReplacer'
1717import {
1818 deleteDefineConfig,
1919+ getDefaultResolveOptions,
1920 hijackVitePluginInject,
2021 resolveFsAllow,
2122} from './utils'
···9293 }
9394 }
94959696+ const resolveOptions = getDefaultResolveOptions()
9597 const config: ViteConfig = {
9698 root,
9799 resolve: {
9898- // by default Vite resolves `module` field, which not always a native ESM module
9999- // setting this option can bypass that and fallback to cjs version
100100- mainFields: [],
100100+ ...resolveOptions,
101101 alias: testConfig.alias,
102102- conditions: ['node'],
103102 },
104103 esbuild: viteConfig.esbuild === false
105104 ? false
···130129 // @ts-ignore Vite 6 compat
131130 environments: {
132131 ssr: {
133133- resolve: {
134134- // by default Vite resolves `module` field, which not always a native ESM module
135135- // setting this option can bypass that and fallback to cjs version
136136- mainFields: [],
137137- conditions: ['node'],
138138- },
132132+ resolve: resolveOptions,
139133 },
140134 },
141135 test: {