styled-components: Unable to to install styled-components in expo app with react 18.0.0

created a expo app

npx create-expo-app purple

that produces following package.json

{
  "name": "purple",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~46.0.8",
    "expo-status-bar": "~1.4.0",
    "react": "18.0.0",
    "react-native": "0.69.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

now i try to install styled-components

npm install styled-components --save

produces following error

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: purple@1.0.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   react@"18.0.0" from the root project
npm ERR!   peer react@">= 16.8.0" from styled-components@5.3.5
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@"^18.2.0" from react-dom@18.2.0
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@">= 16.8.0" from styled-components@5.3.5
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! 
npm ERR! See /Users/manas/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/manas/.npm/_logs/2022-08-21T05_03_49_194Z-debug-0.log
 

npm log

verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using npm@8.15.0
2 info using node@v16.15.0
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 6ms
6 timing config:load:builtin Completed in 7ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/Users/manas/Documents/projects/purple/.npmrc Completed in 1ms
10 timing config:load:project Completed in 3ms
11 timing config:load:file:/Users/manas/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/Users/manas/.npm-global/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 1ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 15ms
19 timing npm:load:configload Completed in 15ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 1ms
22 verbose title npm install styled-components
23 verbose argv "install" "styled-components"
24 timing npm:load:setTitle Completed in 16ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 3ms
27 verbose logfile logs-max:10 dir:/Users/manas/.npm/_logs
28 verbose logfile /Users/manas/.npm/_logs/2022-08-21T05_03_49_194Z-debug-0.log
29 timing npm:load:logFile Completed in 4ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 42ms
33 timing arborist:ctor Completed in 1ms
34 silly logfile start cleaning logs, removing 1 files
35 silly logfile done cleaning log files
36 timing idealTree:init Completed in 536ms
37 timing idealTree:userRequests Completed in 2ms
38 silly idealTree buildDeps
39 silly fetch manifest styled-components@*
40 timing arborist:ctor Completed in 0ms
41 http fetch GET 200 https://registry.npmjs.org/styled-components 688ms (cache revalidated)
42 silly fetch manifest react@18.0.0
43 http fetch GET 200 https://registry.npmjs.org/react 8ms (cache hit)
44 silly fetch manifest react-dom@>= 16.8.0
45 http fetch GET 200 https://registry.npmjs.org/react-dom 91ms (cache revalidated)
46 silly fetch manifest react@^18.2.0
47 timing idealTree Completed in 1354ms
48 timing command:install Completed in 1366ms
49 verbose stack Error: unable to resolve dependency tree
49 verbose stack     at Arborist.[failPeerConflict] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1428:25)
49 verbose stack     at Arborist.[loadPeerSet] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1421:30)
49 verbose stack     at async Arborist.[loadPeerSet] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1362:11)
49 verbose stack     at async Arborist.[buildDepStep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:976:11)
49 verbose stack     at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:218:7)
49 verbose stack     at async Promise.all (index 1)
49 verbose stack     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:154:5)
49 verbose stack     at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:145:5)
49 verbose stack     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:78:5)
50 verbose cwd /Users/manas/Documents/projects/purple
51 verbose Darwin 20.6.0
52 verbose node v16.15.0
53 verbose npm  v8.15.0
54 error code ERESOLVE
55 error ERESOLVE unable to resolve dependency tree
56 error
57 error While resolving: purple@1.0.0
57 error Found: react@18.0.0
57 error node_modules/react
57 error   react@"18.0.0" from the root project
57 error   peer react@">= 16.8.0" from styled-components@5.3.5
57 error   node_modules/styled-components
57 error     styled-components@"*" from the root project
57 error
57 error Could not resolve dependency:
57 error peer react@"^18.2.0" from react-dom@18.2.0
57 error node_modules/react-dom
57 error   peer react-dom@">= 16.8.0" from styled-components@5.3.5
57 error   node_modules/styled-components
57 error     styled-components@"*" from the root project
57 error
57 error Fix the upstream dependency conflict, or retry
57 error this command with --force, or --legacy-peer-deps
57 error to accept an incorrect (and potentially broken) dependency resolution.
57 error
57 error See /Users/manas/.npm/eresolve-report.txt for a full report.
58 verbose exit 1
59 timing npm Completed in 1481ms
60 verbose unfinished npm timer reify 1661058229305
61 verbose unfinished npm timer reify:loadTrees 1661058229314
62 verbose unfinished npm timer idealTree:buildDeps 1661058229853
63 verbose unfinished npm timer idealTree:#root 1661058229854
64 verbose code 1
65 error A complete log of this run can be found in:
65 error     /Users/manas/.npm/_logs/2022-08-21T05_03_49_194Z-debug-0.log

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 5
  • Comments: 17

Most upvoted comments

Worked for me after installing react-dom npx expo install react-dom Thanks @manastunga787

I am trying to install the styled-components I tried reinstalling the npm, I have erased the node_nodules folder, I used --force too, but nothing is working… Can anyone help me?

while installing specify the version also npm install styled-components@5

This kind of problem seems to be about peer dependencies version conflict. You can ignore this kind of problem by default with yarn, or with npm creating a .npmrc file with legacy-peer-deps=true.

im having the same issue with brand new rn project using RN 0.69.0 and React 18.1.0

I ended up running npm install styled-components --force and it worked. I really feel gross with all of those npm WARNs.