Mahdi Ehssani
Mahdi Ehssani

Reputation: 53

Error: Configuration must contain `projectId`

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

Upvotes: 0

Views: 1648

Answers (2)

Hamza Sehouli
Hamza Sehouli

Reputation: 193

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);

Upvotes: 0

Mark G
Mark G

Reputation: 2206

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

Upvotes: 2

Related Questions