I am trying to make nextjs typescript project using sanity.io but im not able to solve this problem. itis showing that createImageUrlBuilder is not a function. [enter image description here][1] here is my sanity module2
[1]:( https://i.stack.imgur.com/HeAAD.png)
CodePudding user response:
You need to pass the sanity client in createImageUrlBuilder instead of config.
import createClient from '@sanity/client';
import createImageUrlBuilder from '@sanity/image-url';
const config = sanityClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
...
});
export const sanityClient = createClient(config);
export const urlFor = (source) => createImageUrlBuilder(client).image(source); // <-----------
CodePudding user response:
First run this command
npm install --save @sanity/image-url
Import createImageUrlBuilder
import createImageUrlBuilder from "@sanity/image-url";
It worked for me this way.