0

i am trying to connect the sanity backend to my nextjs front end project, although I have my id and token in my client.js file but I still face this error: Error: Configuration must contain projectId

import sanityClient from '@sanity/client';
import imageUrlBuilder from '@sanity/image-url';
export  const client = sanityClient ({
    projectID: '****',
    dataset: 'production',
    apiVersion: '2022-03-10',
    useCdn: true,
    token: NEXT_PUBLIC_SANITY_token
});
const builder = imageUrlBuilder(client);
export const urlFor = (source) => builder.image(source);

I really appreciate it if somebody helps me find the solution

Mahdi Ehssani
  • 53
  • 1
  • 5

2 Answers2

2

JavaScript is a case-sensitive language, so change projectID to projectId (notice the lowercase d) in your Sanity client.

Mark G
  • 1,868
  • 1
  • 6
  • 15
0

Replace the projectID key with projectId.

import sanityClient from '@sanity/client';
import imageUrlBuilder from '@sanity/image-url';
export  const client = sanityClient ({
 projectId: '****',
 dataset: 'production',
 apiVersion: '2022-03-10',
 useCdn: true,
 token: NEXT_PUBLIC_SANITY_token
});
const builder = imageUrlBuilder(client);
export const urlFor = (source) => builder.image(source);