Skip to content

Commit

Permalink
fix(resolve): don't set builtinModules to external by default (vite…
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 29, 2024
1 parent d6e6194 commit 2250ffa
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 3 additions & 6 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -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 ?? {},
)
12 changes: 10 additions & 2 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
@@ -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<ResolveOptions>,
ResolvePluginOptions {}
extends Required<Omit<ResolveOptions, 'enableBuiltinNoExternalCheck'>>,
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.

0 comments on commit 2250ffa

Please sign in to comment.