🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Error resolving dependency tree when updating Sanity project's dependencies.

13 replies
Last updated: Apr 24, 2024
I am attempting to update a simple Sanity project to the latest dependencies. Here is my current package.json . Per documentation , I am doing
npm install sanity@latest
and getting the immediate failure:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: loumarc@1.0.0
npm ERR! Found: styled-components@5.3.11
npm ERR! node_modules/styled-components
npm ERR!   styled-components@"^5.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer styled-components@"^6.1" from sanity@3.38.0
npm ERR! node_modules/sanity
npm ERR!   sanity@"3.38.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.
I don't care about
styled-components
. I don't use
styled-components
. I assume the only reason this is in my
package.json
is because Sanity needs it. I tried removing it from my deps, and still get this error. I am at a loss. What is this error trying to tell me? How do I fix it?
Apr 21, 2024, 11:23 AM
I am using node v20.12.2 and npm 10.5.0
Apr 21, 2024, 11:25 AM
... and if the answer is to use
--legacy-peer-deps
well isn't that a temporary solution? Isn't the best practice to keep your dependencies up to date? Feels like
--legacy-peer-deps
is asking for potential future issues.
Apr 21, 2024, 11:34 AM
1. update the styled components
Apr 21, 2024, 1:40 PM
2. if 1 is not working uninstall the package "npm uninstall styled-components" and remove "node modules" and "package-lock.json" and run "npm i"
Apr 21, 2024, 1:41 PM
Did 1, got the same error.
Apr 21, 2024, 2:20 PM
Did 2 because that's the equivalent of "did you turn it off and back on" for Node/npm 🤣
Apr 21, 2024, 2:21 PM
🤷‍♂️
Apr 21, 2024, 2:21 PM
Edit your package.json file, and change the line with styled-components so it looks like this
    "styled-components": "^6.1.8",
Now you have allowed it to update past major version 5, and things should work!

Sometimes it helps to run
npm outdated
to get a list of everything that has an update available.
Apr 22, 2024, 11:59 AM
Thanks
user E
. I think y'all are starting to see my frustration. These are all great ideas. I have done all of these, and I still get this error when running
npm install sanity@latest


npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @sanity/vision@3.14.4
npm ERR! Found: styled-components@6.1.8
npm ERR! node_modules/styled-components
npm ERR!   peer styled-components@"^5.2 || ^6" from @sanity/ui@1.9.3
npm ERR!   node_modules/@sanity/ui
npm ERR!     @sanity/ui@"^1.7.2" from @sanity/vision@3.14.4
npm ERR!     node_modules/@sanity/vision
npm ERR!       @sanity/vision@"^3.14.4" from the root project
npm ERR!     @sanity/ui@"^1.7.4" from the root project
npm ERR!   styled-components@"^6.1.8" from the root project
npm ERR!   1 more (sanity)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer styled-components@"^5.2" from @sanity/vision@3.14.4
npm ERR! node_modules/@sanity/vision
npm ERR!   @sanity/vision@"^3.14.4" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: styled-components@5.3.11
npm ERR! node_modules/styled-components
npm ERR!   peer styled-components@"^5.2" from @sanity/vision@3.14.4
npm ERR!   node_modules/@sanity/vision
npm ERR!     @sanity/vision@"^3.14.4" from the root project
Apr 22, 2024, 1:12 PM
I went back through the advice here and realized I missed a KEY point
user U
made. Remove the
package-lock.json
. After I did that
npm install sanity@latest
worked.
Apr 22, 2024, 1:15 PM
yes it will work i got the same error day before yesterday i am solving it for 6 days after that i read lots of documentations and discussions and finally found it
Apr 22, 2024, 5:47 PM
I guess this is a skill issue on my part. I have to know to remove
package-lock.json
when upgrading
npm
packages?
Apr 24, 2024, 12:06 PM
It is frowned upon, but I sometimes resort to it as well. It shouldn’t be necessary.
Apr 24, 2024, 2:00 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?