diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index 3ca401816c..bad558dd38 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -95,10 +95,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr const componentName = resolveComponentName(fileName, prefixParts) if (resolvedNames.has(componentName + suffix) || resolvedNames.has(componentName)) { - console.warn(`[nuxt] Two component files resolving to the same name \`${componentName}\`:\n` + - `\n - ${filePath}` + - `\n - ${resolvedNames.get(componentName)}` - ) + warnAboutDuplicateComponent(componentName, filePath, resolvedNames.get(componentName) || resolvedNames.get(componentName + suffix)!) continue } resolvedNames.set(componentName + suffix, filePath) @@ -136,10 +133,14 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr continue } - // Ignore component if component is already defined (with same mode) - if (!components.some(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))) { - components.push(component) + const existingComponent = components.find(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode)) + if (existingComponent) { + // Ignore component if component is already defined (with same mode) + warnAboutDuplicateComponent(componentName, filePath, existingComponent.filePath) + continue } + + components.push(component) } scannedPaths.push(dir.path) } @@ -174,3 +175,10 @@ export function resolveComponentName (fileName: string, prefixParts: string[]) { return pascalCase(componentNameParts) + pascalCase(fileNameParts) } + +function warnAboutDuplicateComponent (componentName: string, filePath: string, duplicatePath: string) { + console.warn(`[nuxt] Two component files resolving to the same name \`${componentName}\`:\n` + + `\n - ${filePath}` + + `\n - ${duplicatePath}` + ) +}