GROQ query error: param $slug referenced but not provided
The error you're seeing happens because you're referencing a parameter $slug in your GROQ query but not providing its value when executing the query.
When you use parameters in GROQ (anything starting with $), you need to pass the actual values as a second argument to your fetch() call. Here's how to fix it:
const query = groq`*[_type == "release" && slug.current == $slug][0]`
// Pass the parameter value as the second argument
const result = await client.fetch(query, { slug: 'your-slug-value' })The parameters object maps the parameter name (without the $) to its value. So $slug in your query corresponds to { slug: 'value' } in your parameters.
If you're getting the slug from somewhere like a URL parameter or props, it would look like:
// From Next.js route params
const result = await client.fetch(query, { slug: params.slug })
// Or from a function parameter
async function getRelease(slugValue) {
return await client.fetch(query, { slug: slugValue })
}Using parameters this way is the recommended approach because it's safer than string interpolation - the Sanity client automatically handles proper encoding and prevents GROQ injection issues. Parameters must be JSON-serializable values, which means they can't contain GROQ expressions, making them safe to use with user input.
Show original thread7 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.