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