diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index ede5f47956..4ed83962a8 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -1,7 +1,8 @@ +import { readdir } from 'node:fs/promises' import { basename, dirname, extname, join, relative } from 'pathe' import { globby } from 'globby' import { pascalCase, splitByCase } from 'scule' -import { isIgnored } from '@nuxt/kit' +import { isIgnored, useNuxt } from '@nuxt/kit' // eslint-disable-next-line vue/prefer-import-from-vue import { hyphenate } from '@vue/shared' import { withTrailingSlash } from 'ufo' @@ -30,6 +31,24 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr const resolvedNames = new Map() const files = (await globby(dir.pattern!, { cwd: dir.path, ignore: dir.ignore })).sort() + + // Check if the directory exists (globby will otherwise read it case insensitively on MacOS) + if (files.length) { + const siblings = await readdir(dirname(dir.path)).catch(() => [] as string[]) + + const directory = basename(dir.path) + if (!siblings.includes(directory)) { + const caseCorrected = siblings.find(sibling => sibling.toLowerCase() === directory.toLowerCase()) + if (caseCorrected) { + const nuxt = useNuxt() + const original = relative(nuxt.options.srcDir, dir.path) + const corrected = relative(nuxt.options.srcDir, join(dirname(dir.path), caseCorrected)) + console.warn(`[nuxt] Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`) + continue + } + } + } + for (const _file of files) { const filePath = join(dir.path, _file)