Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing styled components failed in react native

Tags:

react-native

I'm using react native 0.63.4 and react 16.13.1. I try to install 'styled-components' with

npm install --save styled-components

and failed with these messages:

`code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"16.13.1" from the root project
npm ERR!   peer react@">= 16.8.0" from [email protected]
npm ERR!   node_modules/styled-components
npm ERR!     styled-components@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@">= 16.8.0" from [email protected]
npm ERR!   node_modules/styled-components
npm ERR!     styled-components@"*" 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.
npm ERR! `

I was not sure what the problems are. Please if anyone can help me. Thanks.

like image 959
ramose Avatar asked May 13 '26 11:05

ramose


2 Answers

UPDATE https://github.com/npm/cli/issues/2120

Also there is a issue with npm resolving peer-dependencies, npm-CLI currently breaks standard NPM7 installs of several major dependencies, such as for example styled-component, your npm version is 7.+ also

Try downgrading to npm 6 or install another version of styled-components

or you can use yarn to install styled-components

yarn add styled-components
like image 83
S.N.B Avatar answered May 15 '26 01:05

S.N.B


I ended up using yarn to instal styled-components, and it works.

yarn add styled-components
like image 43
ramose Avatar answered May 15 '26 01:05

ramose