Sanity error "Unexpected token" after deleting orderings and preview from schema
Based on the error message you're seeing, this is a common issue related to GROQ syntax in your preview or orderings configuration. The error "Unexpected token '0.', expected expression" typically occurs when you're trying to access an array element using dot notation incorrectly.
The problem likely stems from how you were referencing array items in your preview.select or orderings configuration before deleting them. Even though you've removed the configuration, Sanity Studio might be caching the old settings or there might be remnants in your schema causing the issue.
Common Causes
This error usually happens when you have syntax like:
authors.0.name(incorrect)categories.0.title(incorrect)images.0.asset(incorrect)
In GROQ (which powers preview select and orderings), you need to use bracket notation for array indices, not dot notation.
How to Fix It
Check your schema files for any remaining preview or orderings configurations. Look for patterns like
.0.or.1.in your select statements.Correct array syntax should use brackets:
preview: { select: { authorName: 'authors[0].name', // ✅ Correct categoryTitle: 'categories[0].title' // ✅ Correct } }Clear Studio cache - Sometimes the old configuration persists in cache:
- Delete your
.sanityfolder in your Studio directory - Run
sanity devorsanity startagain - Or try
rm -rf node_modules/.sanity && sanity dev
- Delete your
Check for orderings configuration - If you had custom orderings, make sure they're either properly formatted or completely removed:
orderings: [ { title: 'Author Name', name: 'authorName', by: [ {field: 'authors[0].name', direction: 'asc'} // ✅ Correct bracket notation ] } ]Restart your development server after making changes.
Additional Notes
As mentioned in the preview configuration documentation, when working with arrays in preview select, you should use the correct GROQ syntax with brackets for array indices. The same applies to orderings.
If you've completely removed the preview and orderings configuration and are still seeing the error, there might be a cached version of your schema. Try clearing your browser cache as well, or open Studio in an incognito/private window to rule out browser caching issues.
Show original thread1 reply
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.