diff --git a/packages/nuxt/src/components/loader.ts b/packages/nuxt/src/components/loader.ts index b56271e631..ec8723d0aa 100644 --- a/packages/nuxt/src/components/loader.ts +++ b/packages/nuxt/src/components/loader.ts @@ -43,7 +43,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => { const s = new MagicString(code) // replace `_resolveComponent("...")` to direct import - s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, name: string) => { + s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy(?=[A-Z]))?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, name: string) => { const component = findComponent(components, name, options.mode) if (component) { // @ts-expect-error TODO: refactor to nuxi diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index a09413991e..f37bea63bb 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -96,6 +96,10 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr const componentNameSegments = resolveComponentNameSegments(fileName.replace(/["']/g, ''), prefixParts) const pascalName = pascalCase(componentNameSegments) + if (LAZY_COMPONENT_NAME_REGEX.test(pascalName)) { + logger.warn(`The component \`${pascalName}\` (in \`${filePath}\`) is using the reserved "Lazy" prefix used for dynamic imports, which may cause it to break at runtime.`) + } + if (resolvedNames.has(pascalName + suffix) || resolvedNames.has(pascalName)) { warnAboutDuplicateComponent(pascalName, filePath, resolvedNames.get(pascalName) || resolvedNames.get(pascalName + suffix)!) continue @@ -166,3 +170,5 @@ function warnAboutDuplicateComponent (componentName: string, filePath: string, d `\n - ${duplicatePath}`, ) } + +const LAZY_COMPONENT_NAME_REGEX = /^Lazy(?=[A-Z])/