diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 6c65a2aaaa9012..fe019430605b75 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -4,7 +4,7 @@ import path from 'node:path' import { pathToFileURL } from 'node:url' import { promisify } from 'node:util' import { performance } from 'node:perf_hooks' -import { builtinModules, createRequire } from 'node:module' +import { createRequire } from 'node:module' import colors from 'picocolors' import type { Alias, AliasOptions } from 'dep-types/alias' import { build } from 'esbuild' @@ -621,7 +621,7 @@ export const configDefaults = Object.freeze({ dedupe: [], /** @experimental */ noExternal: [], - // external + external: [], preserveSymlinks: false, alias: [], }, @@ -882,10 +882,7 @@ function resolveEnvironmentResolveOptions( consumer === 'client' || isSsrTargetWebworkerEnvironment ? DEFAULT_CLIENT_CONDITIONS : DEFAULT_SERVER_CONDITIONS.filter((c) => c !== 'browser'), - external: - consumer === 'server' && !isSsrTargetWebworkerEnvironment - ? builtinModules - : [], + enableBuiltinNoExternalCheck: !!isSsrTargetWebworkerEnvironment, }, resolve ?? {}, ) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index c7a113a2b31727..f75798b84abe8e 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -96,6 +96,10 @@ export interface EnvironmentResolveOptions { * @experimental */ external?: string[] | true + /** + * @internal + */ + enableBuiltinNoExternalCheck?: boolean } export interface ResolveOptions extends EnvironmentResolveOptions { @@ -169,8 +173,11 @@ interface ResolvePluginOptions { } export interface InternalResolveOptions - extends Required, - ResolvePluginOptions {} + extends Required>, + ResolvePluginOptions { + /** @internal this is always optional for backward compat */ + enableBuiltinNoExternalCheck?: boolean +} // Defined ResolveOptions are used to overwrite the values for all environments // It is used when creating custom resolvers (for CSS, scanning, etc) @@ -420,6 +427,7 @@ export function resolvePlugin( if (isBuiltin(id)) { if (currentEnvironmentOptions.consumer === 'server') { if ( + options.enableBuiltinNoExternalCheck && options.noExternal === true && // if both noExternal and external are true, noExternal will take the higher priority and bundle it. // only if the id is explicitly listed in external, we will externalize it and skip this error.