Troubleshooting Next.js and Sanity integration with query error
Good news - your createClient configuration looks perfectly fine! The error "ClientError: expected '}' following object body" is actually coming from a malformed GROQ query, not from your client setup.
The Problem
This error almost always means there's a syntax issue in one of your GROQ queries. Based on similar cases in the Sanity community, the most common culprit is a missing comma in your query projection.
The Fix
Check your GROQ queries - especially the one in your [slug] page. Every field in a projection needs a trailing comma, including before nested projections. For example:
*[_type == "property" && slug.current == $pageSlug][0]{
title,
location,
propertyType,
mainImage,
modalidad, // ← Make sure this comma is here!
owner->{
_id,
name,
slug,
image
},
}If you have something like:
modalidad
owner->{Without a comma after modalidad, you'll get the "expected '}' following object body" error.
Other Common Causes
This error can also happen if you write:
{ slug.current }instead of{ "slug": slug.current }(shorthand syntax without proper field naming)- Unmatched braces or brackets
- Missing quotes around custom field names
About Your Setup
The apiVersion you added is correct and necessary - that's not causing the issue. The error is thrown by Sanity's query parser when it encounters malformed GROQ syntax, so look through all your .fetch() calls and double-check the query syntax.
Your client configuration is solid, so once you fix the query syntax, everything should work!
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.