fix(nuxt): skip scanning components that do not produce a name (#22074)

This commit is contained in:
云游君 2023-07-14 21:50:14 +08:00 committed by GitHub
parent 988e75bbc7
commit e3553a36f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,7 +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(`Two component files resolving to the same name \`${componentName}\`:\n` +
console.warn(`[nuxt] Two component files resolving to the same name \`${componentName}\`:\n` +
`\n - ${filePath}` +
`\n - ${resolvedNames.get(componentName)}`
)
@ -130,6 +130,12 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
component = (await dir.extendComponent(component)) || component
}
// Ignore files like `~/components/index.vue` which end up not having a name at all
if (!componentName) {
console.warn(`[nuxt] Component did not resolve to a file name in \`~/${relative(srcDir, filePath)}\`.`)
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)