fix(kit): avoid fallback to normalized path in module loading (#27507)

This commit is contained in:
Pooya Parsa 2024-06-10 18:18:00 +02:00 committed by GitHub
parent 22cd4770c1
commit da28077be3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -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 })

View File

@ -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
}
/**