mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(kit): resolve relative module paths when installing (#20896)
This commit is contained in:
parent
1425a4d537
commit
26861e68ce
@ -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 })
|
||||
|
7
test/fixtures/basic/modules/test/index.ts
vendored
Normal file
7
test/fixtures/basic/modules/test/index.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineNuxtModule } from 'nuxt/kit'
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: {
|
||||
name: 'test'
|
||||
}
|
||||
})
|
1
test/fixtures/basic/nuxt.config.ts
vendored
1
test/fixtures/basic/nuxt.config.ts
vendored
@ -80,6 +80,7 @@ export default defineNuxtConfig({
|
||||
}
|
||||
},
|
||||
modules: [
|
||||
'./modules/test/index',
|
||||
[
|
||||
'~/modules/example',
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user