Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Issue with basic query in Sanity integration with Next.JS project

3 replies
Last updated: Oct 12, 2023
Hi all, I'm integrating Sanity into a Next.JS project but I'm not able to get a basic query working, even though it works in Vision. The error I get is strange and unhelpful:
Unhandled Runtime Error

Error: expected ']' following array body

Here's the code to fetch and display an 'article' page:

import { SanityDocument } from "@sanity/client";

import Article from "@/components/Article";

import { articlePathsQuery, articleQuery } from "@/sanity/lib/queries";

import { client } from "@/sanity/lib/client";

export default async function ArticlePage({params}) {

const article = await client.fetch({articleQuery, params})

return <Article article={article} />;


And here's my query:
`export const articleQuery =
*[_type == "article" && slug.current == $article_id][0]{





Any thoughts/suggestions are much appreciated :)
Oct 12, 2023, 9:33 PM
const article = await client.fetch({articleQuery, params})
Can you try removing the curly braces? E.g.,

const article = await client.fetch(articleQuery, params)
Oct 12, 2023, 9:37 PM
user A
😮 that did it!! thanks Geoff!
Oct 12, 2023, 9:41 PM
Great! No problem!
Oct 12, 2023, 9:41 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?