From 48b48dec0059823dbedeb9008e47bdd07be38a91 Mon Sep 17 00:00:00 2001 From: Preet Mishra Date: Wed, 19 Apr 2023 22:28:43 +0530 Subject: [PATCH] fix(nuxt): handle pages with no content and log warning (#20373) --- packages/nuxt/src/pages/page-meta.ts | 9 ++++++++- test/fixtures/basic/pages/empty.ts | 0 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/basic/pages/empty.ts diff --git a/packages/nuxt/src/pages/page-meta.ts b/packages/nuxt/src/pages/page-meta.ts index 0852c0198e..f970d157bc 100644 --- a/packages/nuxt/src/pages/page-meta.ts +++ b/packages/nuxt/src/pages/page-meta.ts @@ -109,7 +109,14 @@ export const PageMetaPlugin = createUnplugin((options: PageMetaPluginOptions) => } if (!hasMacro && !code.includes('export { default }') && !code.includes('__nuxt_page_meta')) { - s.overwrite(0, code.length, CODE_EMPTY + (options.dev ? CODE_HMR : '')) + if (!code) { + s.append(CODE_EMPTY + (options.dev ? CODE_HMR : '')) + const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href)) + console.error(`The file \`${pathname}\` is not a valid page as it has no content.`) + } else { + s.overwrite(0, code.length, CODE_EMPTY + (options.dev ? CODE_HMR : '')) + } + return result() } diff --git a/test/fixtures/basic/pages/empty.ts b/test/fixtures/basic/pages/empty.ts new file mode 100644 index 0000000000..e69de29bb2