NPM 8 install of craco giving peer dependency issue when used with react-scripts 5.x
When I run npm install on my project that uses react-scripts 5.0.1 and craco 6.4.5 I get the following error because of the change in the legacy peer deps behavior of npm 8:
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! dev @craco/craco@"~6.4.3" from the root project
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! dev react-scripts@"~5.0.1" 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! dev @craco/craco@"~6.4.3" 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 have gone through the following pieces of information:
- https://github.com/dilanx/craco/blob/master/README.md: This calls out that latest release (6.4.5) does not support CRA 5.
- https://github.com/dilanx/craco/issues/426 - I have commented on this issue in the past and also confirmed that 7.0.0-alpha.8 version works on my javascript and typescript project and the error mentioned above does not occur.
- https://github.com/users/dilanx/projects/3 - I have seen this board and there are a fair number of things that have not been picked up and also a sizeable list of things that are still in progress.
- https://github.com/dilanx/craco/issues/457 - I went through this issue and I do not have a similar tree and don't see
craco-antdbeing referenced in my tree and hence I opened this issue.
I have updated my craco.config.js to be compatible with webpack 5 and the changes that brings in. I primarily use craco to help with the creation of named vendor bundles as well as to include the svg optimization (svgo) for @svgr/webpack plugin in my application.
With Node.js 14 (and therefor npm 6 that comes with it) about to be marked end of life (30 Apr 2023) - we have started moving to Node.js 16 which pulls in npm 8 and that is when this issue started popping up.
Given that its been more than 6 months since react-scripts came out with 5.0.1 release and we still don't have a release version of craco that is completely ready, is it possible to have a patch release where the peerDependency of react-scripts is bumped so that https://github.com/dilanx/craco/blob/master/packages/craco/package.json#L37 can look as follows:
"peerDependencies": {
"react-scripts": "^4.0.0 || <=5.0.1" // you can also extend it to patch versions by using ~5.0.0 instead if you need to.
},This should help people move to the latest version of react-scripts (5.0.1) and npm 8. I do understand that people will have to migrate over their craco.config.js to be compatible with webpack 5 but in most cases that just is writing more verbose code in the config file rather than making use of friendly apis that craco provides. However, that would be a trade-off that probably makes sense and buys you time to work on a quality release of craco 7.x, while the community can continue moving forward with the latest release of react-scripts and npm without having to hunt for alternatives to craco. This would be a win-win in my opinion :)
@dilanx I will be more than happy to contribute this change if you are open to it. Please comment here if you have any other alternatives that can work better in this scenario.
Source: dilanx/craco