3

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.

joedotnot
  • 4,810
  • 8
  • 59
  • 91
  • 3
    `npm install react@16 react-dom@16 react-scripts@3`? – Nathan Chu Dec 11 '20 at 13:58
  • @nthnchu No ! this does not run create-react-app. Read up on npm init then you will know it actually runs npx create- – joedotnot Dec 11 '20 at 14:09
  • Oh... You want the create-react-app options for this. I'm not sure about those. – Nathan Chu Dec 11 '20 at 14:15
  • To whoever gave -1, do you think it's not a legitimate question? try answering it instead or point me to the answer :-) – joedotnot Dec 11 '20 at 14:30
  • @Henke Sure it exists, read the question again, I am referring to "react-scripts" 3.4.4 not "create-react-app"; Anyway, it was so long I asked the question, and I don't think the designers of CRA allowed for fine-grained control of versions. – joedotnot Apr 24 '22 at 22:24
  • You are absolutely right. I should have looked at https://www.npmjs.com/package/react-scripts. My mistake. (It guess my prejudice was thinking that CRA and react-scripts would always have the same version. I know better now. Thanks.) – Henke Apr 25 '22 at 08:57
  • Related, I think : https://stackoverflow.com/q/65537734. (I would love to see a solution to your question.) – Henke Apr 25 '22 at 10:49

1 Answers1

1

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 react@XX.XX.XX

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.