mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(kit): use native import for esm modules (#1327)
This commit is contained in:
parent
b332462b2a
commit
f04d6e3b53
@ -1,4 +1,4 @@
|
||||
import { resolveModule, requireModule } from '../utils/cjs'
|
||||
import { resolveModule, requireModule, importModule } from '../utils/cjs'
|
||||
import { resolveAlias } from '../utils/resolve'
|
||||
import type { LegacyNuxtModule, NuxtModule, ModuleMeta, ModuleInstallOptions, ModuleOptions, ModuleSrc } from '../types/module'
|
||||
import type { Nuxt } from '../types/nuxt'
|
||||
@ -32,7 +32,9 @@ export async function installModule (nuxt: Nuxt, installOpts: ModuleInstallOptio
|
||||
let handler: LegacyNuxtModule
|
||||
if (typeof src === 'string') {
|
||||
const _src = resolveModule(resolveAlias(src, nuxt.options.alias), { paths: nuxt.options.modulesDir })
|
||||
handler = requireModule(_src)
|
||||
// TODO: also check with type: 'module' in closest `package.json`
|
||||
const isESM = _src.endsWith('.mjs') || meta.isESM
|
||||
handler = isESM ? await importModule(_src) : requireModule(_src)
|
||||
if (!meta.name) {
|
||||
meta.name = src
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user