'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
Solution 1:[1]
JavaScript is a case-sensitive language, so change projectID to projectId (notice the lowercase d) in your Sanity client.
Solution 2:[2]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark G |
| Solution 2 | Hamza Sehouli |
