Skip to content

Commit ad75c56

Browse files
authoredJan 10, 2025··
fix: resolve.conditions in ResolvedConfig was defaultServerConditions (#19174)
1 parent 282496d commit ad75c56

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
 

‎packages/vite/src/node/__tests__/config.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,35 @@ test('config compat 2', async () => {
481481
]
482482
`)
483483
})
484+
485+
test('config compat 3', async () => {
486+
const config = await resolveConfig({}, 'serve')
487+
expect(config.resolve.conditions).toMatchInlineSnapshot(`
488+
[
489+
"module",
490+
"browser",
491+
"development|production",
492+
]
493+
`)
494+
expect(config.environments.client.resolve.conditions).toMatchInlineSnapshot(`
495+
[
496+
"module",
497+
"browser",
498+
"development|production",
499+
]
500+
`)
501+
expect(config.ssr.resolve?.conditions).toMatchInlineSnapshot(`
502+
[
503+
"module",
504+
"node",
505+
"development|production",
506+
]
507+
`)
508+
expect(config.environments.ssr.resolve?.conditions).toMatchInlineSnapshot(`
509+
[
510+
"module",
511+
"node",
512+
"development|production",
513+
]
514+
`)
515+
})

‎packages/vite/src/node/config.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ function resolveEnvironmentResolveOptions(
867867
alias: Alias[],
868868
preserveSymlinks: boolean,
869869
logger: Logger,
870+
/** undefined when resolving the top-level resolve options */
870871
consumer: 'client' | 'server' | undefined,
871872
// Backward compatibility
872873
isSsrTargetWebworkerEnvironment?: boolean,
@@ -875,11 +876,15 @@ function resolveEnvironmentResolveOptions(
875876
{
876877
...configDefaults.resolve,
877878
mainFields:
878-
consumer === 'client' || isSsrTargetWebworkerEnvironment
879+
consumer === undefined ||
880+
consumer === 'client' ||
881+
isSsrTargetWebworkerEnvironment
879882
? DEFAULT_CLIENT_MAIN_FIELDS
880883
: DEFAULT_SERVER_MAIN_FIELDS,
881884
conditions:
882-
consumer === 'client' || isSsrTargetWebworkerEnvironment
885+
consumer === undefined ||
886+
consumer === 'client' ||
887+
isSsrTargetWebworkerEnvironment
883888
? DEFAULT_CLIENT_CONDITIONS
884889
: DEFAULT_SERVER_CONDITIONS.filter((c) => c !== 'browser'),
885890
enableBuiltinNoExternalCheck: !!isSsrTargetWebworkerEnvironment,

0 commit comments

Comments
 (0)
Please sign in to comment.