How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Sanity 3.16.7 import error in sanity.utils.ts after upgrade from 3.10.3

3 repliesLast updated: Dec 1, 2025

Hello Everyone! Recently I updated my Sanity Studio app by running "npm install sanity@latest" and after updating my app from 3.10.3 version to 3.16.7 I am receiving an error alert (attahed screenshot below). The error points to my sanity.utils.ts file and asks for the import, however I am not able to find any new imports from you Sanity docs, so if anybody had the same issue before, please help!
Here is also my sanity.utils.ts file:

    import { createClient, groq } from "next-sanity";
    import {apiVersion, dataset, projectId} from "./env"
    import { Project } from "../types/Project";
    import { client } from "./lib/client";
    import { Page } from "../types/Page";


    export async function getProjects(): Promise<Project[]> {
        const client = createClient({
            projectId,
            dataset,
            apiVersion,
        })

        return client.fetch(
            groq`*[_type == 'project']{
                _id,
                _createdAt,
                name,
                "slug": slug.current,
                "image": image.asset->url,
            }`
        )
    }


    export async function getProject(slug: string): Promise<Project> {
        const client = createClient({
            projectId,
            dataset,
            apiVersion,
        })

        return client.fetch(
            groq`*[_type == 'project' && slug.current == $slug][0]{
                _id,
                _createdAt,
                name,
                "slug": slug.current,
                "images": images[].asset->url,
            }`,
            {slug}
        )
    }


   
    export async function getPages(): Promise<Page[]> { 
        const client = createClient({
            projectId,
            dataset,
            apiVersion,
        })

        return client.fetch(
            groq`*[_type == 'page']{
                _id,
                _createdAt,
                title,
                "slug": slug.current,
            }`
        )
    }

 
    export async function getPage(slug: string): Promise<Page> {
        const client = createClient({
            projectId,
            dataset,
            apiVersion,
        })

        return client.fetch(
            groq`*[_type == 'page' && slug.current == $slug][0]{
                _id,
                _createdAt, 
                "images": images[].asset->url,
                title,
                "slug": slug.current,
            }`,
            {slug}
        )

    }
AI Update

I can help you with this! Without seeing the exact error message from your screenshot, I'll address the most common issue that occurs after upgrading Sanity Studio and matches the symptoms you're describing.

The Most Likely Issue:

Your code is importing groq from next-sanity, which should still work in current versions. However, based on the SEO context mentioning "groq import" issues, you might be experiencing one of these scenarios:

The Recommended Solution: Switch to defineQuery

The modern approach is to use defineQuery instead of groq. According to the defineQuery documentation, this provides better TypeScript support and enables automatic type generation. Here's how to update your sanity.utils.ts:

import { createClient, defineQuery } from "next-sanity"; // Change groq to defineQuery
import {apiVersion, dataset, projectId} from "./env"
import { Project } from "../types/Project";
import { client } from "./lib/client";
import { Page } from "../types/Page";

export async function getProjects(): Promise<Project[]> {
    const client = createClient({
        projectId,
        dataset,
        apiVersion,
    })

    return client.fetch(
        defineQuery(`*[_type == 'project']{
            _id,
            _createdAt,
            name,
            "slug": slug.current,
            "image": image.asset->url,
        }`)
    )
}

export async function getProject(slug: string): Promise<Project> {
    const client = createClient({
        projectId,
        dataset,
        apiVersion,
    })

    return client.fetch(
        defineQuery(`*[_type == 'project' && slug.current == $slug][0]{
            _id,
            _createdAt,
            name,
            "slug": slug.current,
            "images": images[].asset->url,
        }`),
        {slug}
    )
}

// Apply the same pattern to getPages() and getPage()

Alternative: Remove the Wrapper Entirely

If you don't need type generation, you can simply remove the groq wrapper and use plain template strings:

return client.fetch(
    `*[_type == 'project']{
        _id,
        _createdAt,
        name,
        "slug": slug.current,
        "image": image.asset->url,
    }`
)

The groq template tag was primarily for syntax highlighting and doesn't modify the query string, so removing it won't affect functionality.

Additional Steps:

Why defineQuery is Better:

Using defineQuery gives you:

If you're still seeing the error after trying these solutions, please share the exact error message from your screenshot so we can provide more specific guidance!

Show original thread
3 replies

Was this answer helpful?

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.

Related contributions