From f6b64f6a65761e05abd6de4aea976dfaf240efae Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 18 Jul 2023 17:20:06 +0200 Subject: [PATCH] fix(nuxt): resolve race condition regenerating auto imports (#22201) --- packages/nuxt/src/imports/module.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index f86a6243f9..437671e526 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -87,9 +87,10 @@ export default defineNuxtModule>({ const priorities = nuxt.options._layers.map((layer, i) => [layer.config.srcDir, -i] as const).sort(([a], [b]) => b.length - a.length) const regenerateImports = async () => { - ctx.clearDynamicImports() await ctx.modifyDynamicImports(async (imports) => { - // Scan composables/ + // Clear old imports + imports.length = 0 + // Scan `composables/` const composableImports = await scanDirExports(composablesDirs) for (const i of composableImports) { i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1] @@ -97,6 +98,7 @@ export default defineNuxtModule>({ imports.push(...composableImports) // Modules extending await nuxt.callHook('imports:extend', imports) + return imports }) }