fix(nuxt): warn when definePageMeta does not receive an object (#31156)

This commit is contained in:
Julien Huang 2025-02-27 23:19:04 +01:00 committed by GitHub
parent 1baf3ebad6
commit d337a78755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -247,7 +247,10 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr
foundMeta = true
const pageMetaArgument = node.expression.arguments[0]
if (pageMetaArgument?.type !== 'ObjectExpression') { return }
if (pageMetaArgument?.type !== 'ObjectExpression') {
logger.warn(`\`definePageMeta\` must be called with an object literal (reading \`${absolutePath}\`).`)
return
}
for (const key of extractionKeys) {
const property = pageMetaArgument.properties.find((property): property is Property => property.type === 'Property' && property.key.type === 'Identifier' && property.key.name === key)