diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index dbd51bf226..175d8627b8 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -145,12 +145,16 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial() const r = ({ from }: Import) => resolvedImportPathMap.get(from) - async function cacheImportPaths (imports: Import[]) { - for (const i of imports) { - if (resolvedImportPathMap.has(i.from)) { continue } - let path = resolveAlias(i.from) + + async function cacheImportPaths(imports: Import[]) { + const importSource = Array.from(new Set(imports.map(i => i.from))) + await Promise.all(importSource.map(async (from) => { + if (resolvedImportPathMap.has(from)) { + return + } + let path = resolveAlias(from) if (!isAbsolute(path)) { - path = await tryResolveModule(i.from, nuxt.options.modulesDir).then(async (r) => { + path = await tryResolveModule(from, nuxt.options.modulesDir).then(async (r) => { if (!r) { return r } const { dir, name } = parseNodeModulePath(r) @@ -164,8 +168,8 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial { - const imports = await ctx.getImports().then(r => r.filter(i => !i.type)) + const imports = await ctx.getImports() await cacheImportPaths(imports) return '// Generated by auto imports\n' + ( options.autoImport