4

I am using "npm install -g @sanity/cli sanity init --coupon javascriptmastery2022" everything is workig well until I want to fetch the data from sanity client it says: ***Module not found: Can't resolve '@sanity/client'

1 | import sanityClient from '@sanity/client'; 2 | import imageUrlBuilder from '@sanity/image-url';*** and have checked the package json file and saw there is no '@sanity/client' installed there. then I run npm install -g @sanity/client and npm command works but there is no '@sanity/client' found in the package json, and the error is still the same

I really appreciate if anyone can help me

4 Answers 4

2

Please Install npm i @sanity/client

I think it should be solve

2
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 26, 2022 at 15:05
  • 1
    it worked, thank you so much, i face another problem with the same project: 'Error: Configuration must contain projectId and my code is: import sanityClient from '@sanity/client'; import imageUrlBuilder from '@sanity/image-url'; export const client = sanityClient ({ projectID: '******', dataset: '******', apiVersion: '2022-03-10', useCdn: true, token: NEXT_PUBLIC_SANITY_TOKEN }); const builder = imageUrlBuilder(client); export const urlFor = (source) => builder.image(source); Apr 30, 2022 at 18:33
1

just use --force to install npm package

0

I also stumbled into this error while following the exact same tutorial.

Simply install image-url to your project:

npm install --save @sanity/image-url

0

I got this error recently, I went on sanity doc, to check for @sanity/client, and there you will see the npm install package (npm install -g @sanity/client)

this works as well-------> "npm i @sanity/client"

if this does work, just use "--force" so " npm i @sanity/client --force ", and install in the root folder not the sanity_ecommerce folder, also check the package.json in the root folder to see if it is there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.