Craco - Could not resolve dependency error
Asked Answered
S

10

14

I am trying to setup TailwindCSS in my Create-React-App project and I am trying to install craco so that I need not eject my CRA

When I run the following command npm install @craco/craco, I get unable to resolve dependency tree error. Below is the detail of the error. What should I do? Thanks

npm install @craco/craco
npm ERR! 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-scripts
npm ERR!   react-scripts@"3.4.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react-scripts@"^4.0.0" from @craco/[email protected]
npm ERR! node_modules/@craco/craco
npm ERR!   @craco/craco@"*" 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! 
Sump answered 12/4, 2021 at 9:56 Comment(0)
P
10

This works for me

npm install @craco/craco --save --legacy-peer-deps

With the below line you can also set --legacy-peer-deps permanently as a config option. Try to avoid this as you need to see which npm library/libraries in your project is/are having dependency issues.

npm config set legacy-peer-deps true
Pronoun answered 11/4, 2022 at 8:20 Comment(0)
S
5

I've updated my package react-scripts to the latest version 4.x. by running this command :

npm i react-scripts@latest

then lo and behold, I was able to install craco successfully.

Sump answered 13/4, 2021 at 1:23 Comment(0)
S
3

Run this; it worked for me:

npm config set legacy-peer-deps true
Stomy answered 26/3, 2022 at 23:15 Comment(0)
C
1

Use yarn add, it would solve this for you, you don't need to do anything for the react-scripts version.

Consult answered 20/4, 2022 at 4:27 Comment(0)
T
0

I think the error has to do with the dependency tree.

You have [email protected] but @craco/craco requires [email protected].

Simply run npm i [email protected] and create craco.config.js file

Turbulent answered 15/3, 2022 at 8:11 Comment(0)
S
0

i update my react app and then installed craco 5.05v

Sea answered 29/3, 2022 at 22:45 Comment(0)
B
0

In my case using node v16.15.1 raising this error.
I resolved it by using node v16.13.1 with fixing the version in package.json

  "engines": {
    "node": "16.13.1"
  },

You can also resolve by using yarn not npm.

Bewail answered 31/8, 2022 at 23:57 Comment(0)
S
0

Related issue:

Didn't want to upgrade react-scripts
So tried downgrading craco
It worked fine:

Commands that worked fine are below:

npm uninstall -g craco
npm uninstall -g @craco/craco

npm i -g [email protected]
npm i -g @craco/[email protected]

package.json contents:

"react-scripts": "^4.0.3",
"@craco/craco": "^6.4.3",
"craco": "^0.0.3",

If you are changing package.json then do:

npm i
Sheathbill answered 28/11, 2022 at 4:5 Comment(0)
J
0

I updated craco-less 1.20.0 with craco 6.4.3 and react-scripts 4.0.3, it worked.

"dependencies": {
    "@craco/craco": "^6.4.3",
    "craco-less": "^1.20.0",
    "react-scripts": "4.0.3",
    ...
  },
Jacks answered 22/2, 2023 at 10:1 Comment(0)
D
-4
npm install -f

Could help here.

Denounce answered 25/5, 2022 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.