From c554de79ebaee2bd6e299cbb4c1beaa79ce0bdca Mon Sep 17 00:00:00 2001 From: lazerg Date: Tue, 10 Nov 2026 09:40:14 +0500 Subject: [PATCH 1/2] fix(config): clarify missing unrun error without native TypeScript support --- src/config/file.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/config/file.ts b/src/config/file.ts index 734f9da6c..4164982d3 100644 --- a/src/config/file.ts +++ b/src/config/file.ts @@ -269,7 +269,15 @@ async function tsxImport( async function unrunImport( id: string, ): Promise<[module: unknown, deps: Set]> { - const { unrun } = await importWithError('unrun') + const { unrun } = await importWithError( + 'unrun', + ).catch((error) => { + if (nativeTS) throw error + throw new Error( + `Failed to import module "unrun". It is required to load the config file because the current runtime does not support TypeScript natively. Please install \`unrun\`, or set the --config-loader CLI flag to \`tsx\`.`, + { cause: error }, + ) + }) const { module, dependencies } = await unrun({ path: pathToFileURL(id).href, }) From e88155a5f2eef50a708ce04f2f868f0d6320b4ff Mon Sep 17 00:00:00 2001 From: Kevin Bot Date: Tue, 10 Nov 2026 14:13:14 +0900 Subject: [PATCH 2/2] fix(config): only hint about unrun when the auto loader falls back to it --- src/config/file.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/config/file.ts b/src/config/file.ts index 4164982d3..10030b6d5 100644 --- a/src/config/file.ts +++ b/src/config/file.ts @@ -28,9 +28,8 @@ export async function loadViteConfig( cwd: string, configLoader: InlineConfig['configLoader'], ): Promise<{ config: ViteUserConfig; deps?: Set } | undefined> { - const loader = resolveConfigLoader(configLoader) + const { loader, parser } = createParser(configLoader) debug('Loading Vite config via loader: ', loader) - const parser = createParser(loader) const [result] = await createConfigCoreLoader< [exported: ViteUserConfigExport, deps: Set] >({ @@ -95,10 +94,9 @@ export async function loadConfigFile( } } - const loader = resolveConfigLoader(inlineConfig.configLoader) + const { loader, parser } = createParser(inlineConfig.configLoader) debug('Using config loader:', loader) - const parser = createParser(loader) const sources = overrideConfig ? [ { @@ -171,14 +169,11 @@ const nativeTS = process.features.typescript || process.versions.deno const autoLoader: Parser = isBun || (nativeTS && isSupported) ? 'native' : 'unrun' -function resolveConfigLoader( - configLoader: InlineConfig['configLoader'] = 'auto', -): Parser { - return configLoader === 'auto' ? autoLoader : configLoader -} +function createParser(configLoader: InlineConfig['configLoader'] = 'auto') { + const isAuto = configLoader === 'auto' + const loader: Parser = isAuto ? autoLoader : configLoader -function createParser(loader: Parser) { - return async (filepath: string) => { + const parser = async (filepath: string) => { const basename = path.basename(filepath) const isPkgJson = basename === 'package.json' const isJSON = @@ -196,11 +191,12 @@ function createParser(loader: Parser) { case 'tsx': return tsxImport(filepath) case 'unrun': - return unrunImport(filepath) + return unrunImport(filepath, isAuto) default: throw new Error(`Unknown config loader: ${loader}`) } } + return { loader, parser } } async function nativeImport( @@ -268,13 +264,16 @@ async function tsxImport( async function unrunImport( id: string, + isAuto: boolean, ): Promise<[module: unknown, deps: Set]> { const { unrun } = await importWithError( 'unrun', ).catch((error) => { - if (nativeTS) throw error + // Only explain the fallback when the auto loader picked unrun because the + // runtime lacks native TypeScript support; an explicit choice needs no hint. + if (!isAuto || isBun || nativeTS) throw error throw new Error( - `Failed to import module "unrun". It is required to load the config file because the current runtime does not support TypeScript natively. Please install \`unrun\`, or set the --config-loader CLI flag to \`tsx\`.`, + `Failed to import module "unrun". The current runtime does not support TypeScript natively, so tsdown loads the config file with \`unrun\` by default. Please install \`unrun\`, or set the --config-loader CLI flag to another installed loader, such as \`tsx\`.`, { cause: error }, ) })