ClientError: expected '}' following object body in next-sanity createClient

15 replies
Last updated: Jan 28, 2026
Good morning! I'm trying to connect my sanity app with Next.js using createClient from "next-sanity", but I keep getting this error: "*ClientError: expected '}' following object body*"
This is my code:

import { createClient } from "next-sanity"

export const sanityClient = createClient({

dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",

projectId: "ekdlavlv",

apiVersion: "2022-03-25",

useCdn: process.env.NODE_ENV === "production",

})
AI Update

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!

Show original thread
15 replies

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.

Was this answer helpful?