πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Error when creating a client in Next.js with Sanity.io integration

10 replies
Last updated: Jul 6, 2023
Hello, yesterday i started to work on a new website and i want to fetch my data from my sanity the problem is when i try to create a client it gives me this error :
Error: It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import.
i am on the nextjs 13 version and sanity v3 here my code

import { createClient } from 'next-sanity'

import { apiVersion, dataset, projectId, useCdn } from '../env'

export const client = createClient({
  apiVersion,
  dataset,
  projectId,
  useCdn,
  token: process.env.NEXT_PUBLIC_SANITY_EDITOR,
})
the problem is line 5, can someone help me ? thanks in advance
Jun 30, 2023, 12:02 PM
I found the error i got the wrong version of next-sanity do i upgraded it and it works now
Jun 30, 2023, 12:39 PM
You don't really need to use this line:
import { apiVersion, dataset, projectId, useCdn } from '../env'
just like
token: process.env.NEXT_PUBLIC_SANITY_EDITOR,
you can do the same for the others too
Jun 30, 2023, 1:04 PM
Hey, i also have got the same error, could you help me with this issue? how did you fix it?
Jun 30, 2023, 1:11 PM
go into your package json and update your next-sanity version to the latest then do npm i and it should fix the problem
Jun 30, 2023, 1:14 PM
it says
"next-sanity": "^4.3.3",
in my package.json
Jun 30, 2023, 1:15 PM
this is strange as it was working a while back and now i see this issue πŸ˜•
Jun 30, 2023, 1:20 PM
works now, strange
Jun 30, 2023, 1:22 PM
user D
what version of
next-sanity
are you now seeing that is working for you?
Jun 30, 2023, 10:19 PM
it's the same as the one i posted herem
"next-sanity": "^4.3.3"
Jul 1, 2023, 3:02 AM
Hiya, was there a fix to this issue? I'm also running
"next-sanity": "^4.3.3"
and seeing the same error. TY!
Jul 6, 2023, 8:01 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?