From da28077be3fb3265c04fe5defa5b9f42cc8408aa Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 10 Jun 2024 18:18:00 +0200 Subject: [PATCH] fix(kit): avoid fallback to normalized path in module loading (#27507) --- packages/kit/src/module/install.ts | 2 +- packages/kit/src/resolve.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/module/install.ts b/packages/kit/src/module/install.ts index d283388a63..153aab0bd8 100644 --- a/packages/kit/src/module/install.ts +++ b/packages/kit/src/module/install.ts @@ -84,7 +84,7 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n let error: unknown for (const path of paths) { try { - const src = await resolvePath(path) + const src = await resolvePath(path, { fallbackToOriginal: true }) // Prefer ESM resolution if possible nuxtModule = await importModule(src, nuxt.options.modulesDir).catch(() => null) ?? requireModule(src, { paths: nuxt.options.modulesDir }) diff --git a/packages/kit/src/resolve.ts b/packages/kit/src/resolve.ts index 8bdf0693c3..392dec86d8 100644 --- a/packages/kit/src/resolve.ts +++ b/packages/kit/src/resolve.ts @@ -23,6 +23,13 @@ export interface ResolvePathOptions { * @default false */ virtual?: boolean + + /** + * Whether to fallback to the original path if the resolved path does not exist instead of returning the normalized input path. + * + * @default false + */ + fallbackToOriginal?: boolean } /** @@ -99,7 +106,7 @@ export async function resolvePath (path: string, opts: ResolvePathOptions = {}): } // Return normalized input - return path + return opts.fallbackToOriginal ? _path : path } /**