dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.41k stars 501 forks source link

NPM 8 install of craco giving peer dependency issue when used with react-scripts 5.x #459

Open gauravshah27 opened 1 year ago

gauravshah27 commented 1 year ago

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/craco@6.4.5
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: react-node16-test@0.1.0
npm ERR! Found: react-scripts@5.0.1
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/craco@6.4.5
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:

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.

dilanx commented 1 year ago

Thanks for the great suggestion @gauravshah27! Although I see what you're getting at, I think it might be better to hold off until the 7.0.0 release. I plan to release craco 7 within the next week because the latest alpha version is stable enough to be used with CRA 5. The things that remain on the project board are mainly just extra enhancements or other issues that may have already existed with older craco versions, and those can be added in a future minor update. The primary goal of craco 7 is simply to support CRA 5, which it seems like the alpha versions are doing.

I apologize for the long delay, but I think we're finally reaching a point where craco 7 can be released. I plan on making a couple of final adjustments and finding a solution to #447 over the next couple of days, and with a release so close, it wouldn't really make sense to support CRA 5 with such an old version of craco and have people mess with their configs just to have to put it back shortly after.

Let me know what you think!

gauravshah27 commented 1 year ago

@dilanx I feel much better after reading your response. It makes a lot of sense if you are planning to release the enhancements, as you mentioned, in future minor updates and its best to wait for the craco 7 release if the release is happening within the next week. So I agree with you and will wait eagerly for the release to drop. Thanks again for the quick turn around and for all the work that you are putting in.

If its ok - I will leave this issue open until the craco 7 release drops and then will come back and close it after we have the release and we have confirmed that it works as expected.

gauravshah27 commented 1 year ago

@dilanx just reaching out to see if we have a more concrete release date for the 7.x release ?

dilanx commented 1 year ago

@gauravshah27 it should be out by Monday!

vongohren commented 1 year ago

Im stil getting this issue with a fresh install

Alevale commented 2 months ago

Same here, trying to add typescript with npm >8 (9 in my case) still gives the above issue.

@dilanx Is there any fix for this?