mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): use resolvePath
to handle edge cases for modules (#20975)
This commit is contained in:
parent
2d680455ae
commit
980728275a
@ -1,11 +1,11 @@
|
||||
import { lstatSync } from 'node:fs'
|
||||
import type { Nuxt, NuxtModule } from '@nuxt/schema'
|
||||
import { dirname, isAbsolute, normalize, resolve } from 'pathe'
|
||||
import { dirname, isAbsolute } from 'pathe'
|
||||
import { isNuxt2 } from '../compatibility'
|
||||
import { useNuxt } from '../context'
|
||||
import { requireModule } from '../internal/cjs'
|
||||
import { importModule } from '../internal/esm'
|
||||
import { resolveAlias } from '../resolve'
|
||||
import { resolveAlias, resolvePath } from '../resolve'
|
||||
|
||||
/** Installs a module on a Nuxt instance. */
|
||||
export async function installModule (moduleToInstall: string | NuxtModule, _inlineOptions?: any, _nuxt?: Nuxt) {
|
||||
@ -53,11 +53,7 @@ async function normalizeModule (nuxtModule: string | NuxtModule, inlineOptions?:
|
||||
|
||||
// Import if input is string
|
||||
if (typeof nuxtModule === 'string') {
|
||||
let src = resolveAlias(nuxtModule)
|
||||
if (src.match(/^\.{1,2}\//)) {
|
||||
src = resolve(nuxt.options.rootDir, src)
|
||||
}
|
||||
src = normalize(src)
|
||||
const src = await resolvePath(nuxtModule)
|
||||
try {
|
||||
// Prefer ESM resolution if possible
|
||||
nuxtModule = await importModule(src, nuxt.options.modulesDir).catch(() => null) ?? requireModule(src, { paths: nuxt.options.modulesDir })
|
||||
|
2
test/fixtures/basic/nuxt.config.ts
vendored
2
test/fixtures/basic/nuxt.config.ts
vendored
@ -80,7 +80,7 @@ export default defineNuxtConfig({
|
||||
}
|
||||
},
|
||||
modules: [
|
||||
'./modules/test/index',
|
||||
'./modules/test',
|
||||
[
|
||||
'~/modules/example',
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user