diff --git a/src/options.ts b/src/options.ts index f6a777bff9..1b6b10fa92 100644 --- a/src/options.ts +++ b/src/options.ts @@ -3,7 +3,11 @@ import { loadConfig, watchConfig, WatchConfigOptions } from "c12"; import { klona } from "klona/full"; import { camelCase } from "scule"; import { defu } from "defu"; -import { resolveModuleExportNames, resolvePath as resolveModule } from "mlly"; +import { + resolveModuleExportNames, + resolvePath as resolveModule, + parseNodeModulePath, +} from "mlly"; import escapeRE from "escape-string-regexp"; import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash } from "ufo"; import { isTest, isDebug } from "std-env"; @@ -314,9 +318,16 @@ export async function loadOptions( serverAsset.dir = resolve(options.srcDir, serverAsset.dir); } - for (const pkg of ["defu", "h3", "radix3"]) { - if (!options.alias[pkg]) { - options.alias[pkg] = await resolveModule(pkg, { url: import.meta.url }); + // Dedup built-in dependencies + for (const pkg of ["defu", "h3", "radix3", "unstorage"]) { + const entryPath = await resolveModule(pkg, { url: import.meta.url }); + const { dir, name } = parseNodeModulePath(entryPath); + if (!dir || !name) { + continue; + } + if (!options.alias[pkg + "/"]) { + const pkgDir = join(dir, name); + options.alias[pkg + "/"] = pkgDir; } }