Remove `groq` from `client.fetch()` in Next.js tutorial Chapter 4
Thank you for reporting this! You're absolutely right, and I appreciate you taking the time to help improve the tutorial for other developers.
The issue you've identified is actually about how the groq package is being used. Looking at the tutorial, there's an inconsistency in Chapter 4's code example.
What's happening:
In the code example you mentioned, groq is being used as a template literal tag (like groq`query here`), but the groq package isn't imported at the top of that particular code snippet. This causes an error because groq is undefined.
The fix (as you discovered):
You have two options:
Remove the
groqtag and just use a plain template literal string (which is what you did):const paths = await client.fetch( `*[_type == "post" && defined(slug.current)][].slug.current` )Or import
groqat the top of the file (which the tutorial does later in the same chapter):import groq from 'groq'
The tutorial actually introduces the groq import later when dealing with categories, which is why the earlier example doesn't work as written. The groq package from npm is useful for syntax highlighting in supported editors, but it's not strictly necessary for the query to work—it's essentially a pass-through function that returns the string unchanged.
This is definitely worth correcting in the tutorial. You can report issues like this directly on the Sanity documentation GitHub repository or reach out through the Sanity Community Slack where the documentation team is active and responsive to feedback.
Thanks again for helping make the learning experience smoother for beginners! These kinds of reports are invaluable for keeping the documentation accurate and beginner-friendly.
Show original thread10 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.