fix(kit): resolve relative module paths when installing (#20896)

This commit is contained in:
Daniel Roe 2023-05-20 23:10:52 +01:00 committed by GitHub
parent 1425a4d537
commit 26861e68ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { lstatSync } from 'node:fs'
import type { Nuxt, NuxtModule } from '@nuxt/schema'
import { dirname, isAbsolute, normalize } from 'pathe'
import { dirname, isAbsolute, normalize, resolve } from 'pathe'
import { isNuxt2 } from '../compatibility'
import { useNuxt } from '../context'
import { requireModule } from '../internal/cjs'
@ -53,7 +53,11 @@ async function normalizeModule (nuxtModule: string | NuxtModule, inlineOptions?:
// Import if input is string
if (typeof nuxtModule === 'string') {
const src = normalize(resolveAlias(nuxtModule))
let src = resolveAlias(nuxtModule)
if (src.match(/^\.{1,2}\//)) {
src = resolve(nuxt.options.rootDir, src)
}
src = normalize(src)
try {
// Prefer ESM resolution if possible
nuxtModule = await importModule(src, nuxt.options.modulesDir).catch(() => null) ?? requireModule(src, { paths: nuxt.options.modulesDir })

View File

@ -0,0 +1,7 @@
import { defineNuxtModule } from 'nuxt/kit'
export default defineNuxtModule({
meta: {
name: 'test'
}
})

View File

@ -80,6 +80,7 @@ export default defineNuxtConfig({
}
},
modules: [
'./modules/test/index',
[
'~/modules/example',
{