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,23 +79,26 @@ export async function loadNuxtModuleInstance (nuxtModule: string | NuxtModule, n
|
|||||||
|
|
||||||
// Import if input is string
|
// Import if input is string
|
||||||
if (typeof nuxtModule === 'string') {
|
if (typeof nuxtModule === 'string') {
|
||||||
const paths = [join(nuxtModule, 'nuxt'), join(nuxtModule, 'module'), nuxtModule, join(nuxt.options.rootDir, nuxtModule)]
|
|
||||||
let error: unknown
|
let error: unknown
|
||||||
for (const path of paths) {
|
const paths = [join(nuxtModule, 'nuxt'), join(nuxtModule, 'module'), nuxtModule, join(nuxt.options.rootDir, nuxtModule)]
|
||||||
try {
|
|
||||||
const src = jiti.esmResolve(path)
|
|
||||||
nuxtModule = await jiti.import(src) as NuxtModule
|
|
||||||
|
|
||||||
// nuxt-module-builder generates a module.json with metadata including the version
|
for (const parentURL of nuxt.options.modulesDir) {
|
||||||
const moduleMetadataPath = join(dirname(src), 'module.json')
|
for (const path of paths) {
|
||||||
if (existsSync(moduleMetadataPath)) {
|
try {
|
||||||
buildTimeModuleMeta = JSON.parse(await fsp.readFile(moduleMetadataPath, 'utf-8'))
|
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
|
||||||
|
const moduleMetadataPath = join(dirname(src), 'module.json')
|
||||||
|
if (existsSync(moduleMetadataPath)) {
|
||||||
|
buildTimeModuleMeta = JSON.parse(await fsp.readFile(moduleMetadataPath, 'utf-8'))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
} catch (_err: unknown) {
|
||||||
|
error = _err
|
||||||
}
|
}
|
||||||
break
|
|
||||||
} catch (_err: unknown) {
|
|
||||||
error = _err
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
if (typeof nuxtModule !== 'string') { break }
|
||||||
}
|
}
|
||||||
if (typeof nuxtModule !== 'function' && error) {
|
if (typeof nuxtModule !== 'function' && error) {
|
||||||
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user