Skip to content

Commit 2250ffa

Browse files
authored
fix(resolve): don't set builtinModules to external by default (#18821)
1 parent d6e6194 commit 2250ffa

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

packages/vite/src/node/config.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'node:path'
44
import { pathToFileURL } from 'node:url'
55
import { promisify } from 'node:util'
66
import { performance } from 'node:perf_hooks'
7-
import { builtinModules, createRequire } from 'node:module'
7+
import { createRequire } from 'node:module'
88
import colors from 'picocolors'
99
import type { Alias, AliasOptions } from 'dep-types/alias'
1010
import { build } from 'esbuild'
@@ -621,7 +621,7 @@ export const configDefaults = Object.freeze({
621621
dedupe: [],
622622
/** @experimental */
623623
noExternal: [],
624-
// external
624+
external: [],
625625
preserveSymlinks: false,
626626
alias: [],
627627
},
@@ -882,10 +882,7 @@ function resolveEnvironmentResolveOptions(
882882
consumer === 'client' || isSsrTargetWebworkerEnvironment
883883
? DEFAULT_CLIENT_CONDITIONS
884884
: DEFAULT_SERVER_CONDITIONS.filter((c) => c !== 'browser'),
885-
external:
886-
consumer === 'server' && !isSsrTargetWebworkerEnvironment
887-
? builtinModules
888-
: [],
885+
enableBuiltinNoExternalCheck: !!isSsrTargetWebworkerEnvironment,
889886
},
890887
resolve ?? {},
891888
)

packages/vite/src/node/plugins/resolve.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export interface EnvironmentResolveOptions {
9696
* @experimental
9797
*/
9898
external?: string[] | true
99+
/**
100+
* @internal
101+
*/
102+
enableBuiltinNoExternalCheck?: boolean
99103
}
100104

101105
export interface ResolveOptions extends EnvironmentResolveOptions {
@@ -169,8 +173,11 @@ interface ResolvePluginOptions {
169173
}
170174

171175
export interface InternalResolveOptions
172-
extends Required<ResolveOptions>,
173-
ResolvePluginOptions {}
176+
extends Required<Omit<ResolveOptions, 'enableBuiltinNoExternalCheck'>>,
177+
ResolvePluginOptions {
178+
/** @internal this is always optional for backward compat */
179+
enableBuiltinNoExternalCheck?: boolean
180+
}
174181

175182
// Defined ResolveOptions are used to overwrite the values for all environments
176183
// It is used when creating custom resolvers (for CSS, scanning, etc)
@@ -420,6 +427,7 @@ export function resolvePlugin(
420427
if (isBuiltin(id)) {
421428
if (currentEnvironmentOptions.consumer === 'server') {
422429
if (
430+
options.enableBuiltinNoExternalCheck &&
423431
options.noExternal === true &&
424432
// if both noExternal and external are true, noExternal will take the higher priority and bundle it.
425433
// only if the id is explicitly listed in external, we will externalize it and skip this error.

0 commit comments

Comments
 (0)