Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install react (v16.x) and react-scripts (3.x)

As per the title, I don't want to use

npx create-react-app app-name

, because that command installs react (17x) and react-scripts (4.x)

I tried

npm init react-app app-name --scripts-version 3.4.4

, but even though it installs react-scripts (v3.4.4), it still installs react (17.x)

Also, this gives another error:

error : Cannot find module 'cra-template'

EDIT: To clarify, I want to use CRA for sure. Just not with the current versions of react-17, react-dom-17, and react-scripts-4

I also don't want to waste time installing v17.x, and v4.x, delete them manually, modify package.json to the versions I want, and npm (re-)install. That will work, but it's not the point.

like image 773
joedotnot Avatar asked Aug 05 '26 06:08

joedotnot


1 Answers

npm init react-app appname --scripts-version <XX.XX.XX>
or sudo npm init react-app appname --scripts-version <XX.XX.XX>

The version number <XX.XX.XX> is for react-scripts to generate a specific react-app based on dependent version of the initiated react-scripts module.

You will have to do some legwork to see which react-scripts version relates to the specific react version when initializing a building of a new react-app.

React Versions: https://reactjs.org/versions/ React Scripts Versions: https://www.npmjs.com/package/react-scripts

If it keeps installing the newest React version

Enter npm uninstall react,

Then npm install [email protected]

Where XX.XX.XX is your target number

You will have to do the same for react-dom (same ver# as react) and react-scripts.

Also the @testing-library dependencies may also need uninstalling (There should be 3 on instantiation - they will not work with previous versions (pre-v17 React))

I came across this exact same problem today, and that was my solution.

like image 83
Vincent Czubatiuk Avatar answered Aug 07 '26 22:08

Vincent Czubatiuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!