Home > Software design >  How to resolve npm ERR! ERESOLVE unable to resolve dependency tree - simple react lightbox?
How to resolve npm ERR! ERESOLVE unable to resolve dependency tree - simple react lightbox?

Time:06-04

I'm trying to resolve an error with my Gatsby project.

I got the following error when I run npm update in my CLI:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.2" from [email protected]
npm ERR! node_modules/simple-react-lightbox
npm ERR!   simple-react-lightbox@"^3.6.9-0" 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.

When I build (gatsby build) the website via the CLI it works, but when I deploy it to Netlify I get the same error:

4:05:39 PM: npm ERR! code ERESOLVE
4:05:39 PM: npm ERR! ERESOLVE could not resolve
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! While resolving: [email protected]
4:05:39 PM: Creating deploy upload records
4:05:39 PM: npm ERR! Found: [email protected]
4:05:39 PM: npm ERR! node_modules/react
4:05:39 PM: npm ERR!   react@"^18.1.0" from the root project
4:05:39 PM: npm ERR!   peer react@">=16.8 || ^17.0.0" from [email protected]
4:05:39 PM: npm ERR!   node_modules/framer-motion
4:05:39 PM: npm ERR!     framer-motion@"^4.1.17" from [email protected]
4:05:39 PM: npm ERR!     node_modules/simple-react-lightbox
4:05:40 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
4:05:39 PM: npm ERR!       simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR!   15 more (nano-css, react-dom, react-helmet, react-masonry-css, ...)
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Could not resolve dependency:
4:05:39 PM: npm ERR! peer react@"^17.0.2" from [email protected]
4:05:39 PM: npm ERR! node_modules/simple-react-lightbox
4:05:39 PM: npm ERR!   simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Conflicting peer dependency: [email protected]
4:05:39 PM: npm ERR! node_modules/react
4:05:39 PM: npm ERR!   peer react@"^17.0.2" from [email protected]
4:05:39 PM: npm ERR!   node_modules/simple-react-lightbox
4:05:39 PM: npm ERR!     simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Fix the upstream dependency conflict, or retry
4:05:39 PM: npm ERR! this command with --force, or --legacy-peer-deps
4:05:39 PM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Any ideas on how to resolve this?

CodePudding user response:

I faced similar problem some minutes ago, but I was able to solve it by forcefully installing it using the --force flag, so you'd install it by:

npm install --force simple-react-lightbox

What I believe the problem is, is that the dependency/package you want to install is built upon react v17.x and you're working with a project on react v18.x

I hope this solves your problem.

CodePudding user response:

I see that the package has been deprecated. It's no longer been supported since a short time ago. I've downgraded react from 17 to 18. That seems to work.

https://www.npmjs.com/package/simple-react-lightbox

My steps:

  1. downgraded react 18 to 17 (npm install --save [email protected] [email protected])
  2. Deleted Gatsby cache gatsby clean
  3. Deleted node_modules and package-lock.json
  4. Reinstalled npm npm install
  • Related