Search code examples
next.jssanity

Using sanity with next js: Client error "Must be an attribute or a string key"


I'm working with next-sanity for creating the client, but I keep getting the " Client error: Must be an attribute or a string key" error.

This is my config:

import { createClient, createImageUrlBuilder } from "next-sanity"

const config = {

  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
  projectId: "ekdlavlv",
  useCdn: process.env.NODE_ENV === "production",

}

export const urlFor = (source) => createImageUrlBuilder(config).image(source)

// Set up the client for fetching data in the getProps page functions
export const sanityClient = createClient(config)

Solution

  • If you're using next-sanity@0.5.0 or later, you won't import createImageUrlBuilder from next-sanity but from @sanity/image-url. See here for the migration details.