mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(kit): try resolving module path from each node_modules dir
This commit is contained in:
parent
33e2d0a5f3
commit
097105fb2b
@ -79,11 +79,13 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
||||
|
||||
// Import if input is string
|
||||
if (typeof nuxtModule === 'string') {
|
||||
const paths = [join(nuxtModule, 'nuxt'), join(nuxtModule, 'module'), nuxtModule, join(nuxt.options.rootDir, nuxtModule)]
|
||||
let error: unknown
|
||||
const paths = [join(nuxtModule, 'nuxt'), join(nuxtModule, 'module'), nuxtModule, join(nuxt.options.rootDir, nuxtModule)]
|
||||
|
||||
for (const parentURL of nuxt.options.modulesDir) {
|
||||
for (const path of paths) {
|
||||
try {
|
||||
const src = jiti.esmResolve(path)
|
||||
const src = jiti.esmResolve(path, { parentURL })
|
||||
nuxtModule = await jiti.import(src) as NuxtModule
|
||||
|
||||
// nuxt-module-builder generates a module.json with metadata including the version
|
||||
@ -94,9 +96,10 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
||||
break
|
||||
} catch (_err: unknown) {
|
||||
error = _err
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (typeof nuxtModule !== 'string') { break }
|
||||
}
|
||||
if (typeof nuxtModule !== 'function' && error) {
|
||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||
throw error
|
||||
|
Loading…
Reference in New Issue
Block a user