3

I'm trying to make a nextjs/sanity project at the moment, and I think I may have installed sanity client twice, but not entirely sure.

This is the error I'm getting in the command terminal:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: next-sanity-image@3.2.1
npm ERR! Found: @sanity/client@3.3.6
npm ERR! node_modules/@sanity/client
npm ERR!   @sanity/client@"^3.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @sanity/client@"^2.11.0" from next-sanity-image@3.2.1
npm ERR! node_modules/next-sanity-image
npm ERR!   next-sanity-image@"^3.2.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @sanity/client@2.23.2
npm ERR! node_modules/@sanity/client
npm ERR!   peer @sanity/client@"^2.11.0" from next-sanity-image@3.2.1
npm ERR!   node_modules/next-sanity-image
npm ERR!     next-sanity-image@"^3.2.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

I have tried npm install --legacy-peer-deps but it isn't fixing this error. I am currently trying to do npm install --save @babel/preset-react, which is what triggered these error messages. What is it that I need to do?

paparonnie
  • 170
  • 8
  • delete node modules, delete package-lock.json and run npm i again – KcH Sep 08 '22 at 02:39
  • Are you sure none of the answers in [Fix the upstream dependency conflict installing NPM packages](https://stackoverflow.com/questions/64936044/fix-the-upstream-dependency-conflict-installing-npm-packages) work for you? – juliomalves Oct 02 '22 at 18:07

2 Answers2

0

I think your sanity client is deprecated. Try to delete all your sanity dependencies (@sanity/client@"^3.2.0" / "next-sanity-image": "^3.2.1") listed by your error message in your package.json.

Then, simply try to re-install Sanity --> npm i sanity.

And it should work !

0

The warning means the @sanity/client package's version installed in your project is not compatible with the version specified in the peerDependencies field of next-sanity-image@3.2.1.

next-sanity-image@3.2.1 package demands @sanity/client as its peer dependency with ^2.11.0 version. So, you need to install the @sanity/client@^2.11.0 in your project.

$ npm view next-sanity-image@3.2.1 peerDependencies
{
  '@sanity/client': '^2.11.0',
  next: '^11.0.0 || ^12.0.0',
  react: '^17.0.2'
}

Let's downgrade the @sanity/client package to the ^2.11.0 version and install that package again.

$ npm i @sanity/client@^2.11.0 -S

up to date, audited 354 packages in 1s

43 packages are looking for funding
  run `npm fund` for details

10 vulnerabilities (5 moderate, 5 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
$ npm i next-sanity-image@^3.2.1 -S 

added 2 packages, and audited 354 packages in 3s

43 packages are looking for funding
  run `npm fund` for details

10 vulnerabilities (5 moderate, 5 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

List installed packages:

$ npm ls --depth 0
peer-deps-issue@ /home/lindu/workspace/peer-deps-issue
├── @sanity/client@2.23.2
├── next-sanity-image@3.2.1
├── next@11.1.4
├── react-dom@17.0.2
└── react@17.0.2

The warning is gone.

Lin Du
  • 88,126
  • 95
  • 281
  • 483