Troubleshooting a Query Error in Nuxt
This is a syntax error in your GROQ query - you're missing a closing brace! Looking at your query structure, the issue is that you have a backtick in the wrong place that's breaking the template literal.
Here's the corrected version:
const query = groq`*[_type == "project"]{
title,
mainImage,
createdAt,
"excerpt": array::join(string::split((body[0].children[0].text), "")[0..100], "") + "..."
}`;The problems in your original code were:
- Extra backtick after the opening brace - You had
*[_type == "project"]{which broke the template literal - Missing closing brace - The GROQ projection
{}needs to be properly closed before the closing backtick
Also, a friendly tip: this excerpt approach will work, but it's a bit fragile since it directly accesses body[0].children[0].text which will break if your body structure is different. You might want to consider using the pt::text() function for Portable Text, which is more robust:
const query = groq`*[_type == "project"]{
title,
mainImage,
createdAt,
"excerpt": pt::text(body)[0..100] + "..."
}`;This will extract plain text from your entire Portable Text body field regardless of its structure, then take the first 100 characters. Much cleaner! π
Sanity β Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.