10

I want to create a React app using the command

npx create-react-app my-app

But I want to make sure I can choose the React version. I want a version that can't use hooks, so I want to force a React version before 16.8 (in which hooks were released).

How or where do I find the version to use?
I have followed a tutorial that gave me a command like

npx create-react-app reactjs-app --scripts-version 1.1.5

How can I create an app with for example React version 16.7?

My goal is to get the latest version before which hooks were released.

Henke
  • 4,445
  • 3
  • 31
  • 44
Ana S.
  • 115
  • 1
  • 1
  • 5
  • Maybe [this](https://stackoverflow.com/questions/49828493/upgrading-react-version-and-its-dependencies-by-reading-package-json) answer can help you – ramilabbaszade Jan 02 '21 at 10:20
  • Does this answer your question? [How to use create-react-app with an older React version?](/q/46566830/90527) – outis Aug 03 '22 at 20:20

2 Answers2

16

According the documentation the syntax for npx is:

npx [options] <command>[@version] [command-arg]...

If you want react version 16.7 you have to find out which version of create-react-app installs react 16.7 because the version numbers are not the same. If I'm correct version 3.4.1 of create-react-app installs the latest version of react before they introduce hooks.

can simply run:

npx create-react-app@3.4.1 my-app 
Stefan van de Vooren
  • 2,524
  • 22
  • 19
  • 4
    This no longer works with v4.0.3. See the issue at: https://github.com/facebook/create-react-app/issues/11816 – Dheeraj Vepakomma Jan 02 '22 at 08:54
  • I fail to understand this answer. I tried `npx create-react-app@3.4.1 my-app` (on Windows 10) and got `'create-react-app' is not recognized as an internal or external command`. Have tried it several times – always with the same result. ~ * ~ Installing the latest version via `npx create-react-app my-app` works just fine. – Henke Apr 24 '22 at 12:14
2

Some packages may use a different name for the package and the tool, causing some forms of the version specifier to fail when the plain command works:

$ npx uglifyjs --version
uglify-js 3.14.4

$ npx uglifyjs@3.10.0 --version
npm ERR! code ETARGET
npm ERR! notarget No matching version found for uglifyjs@3.10.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
[..]
Install for [ 'uglifyjs@3.10.0' ] failed with code 1

In this case, using -p / --package, or specifying the package name instead, will allow npx to work as expected:

$ npx --package uglify-js@3.10.0 uglifyjs --version
npx: installed 1 in 0.631s
uglify-js 3.10.0

$ npx uglify-js@3.10.0 --version
npx: installed 1 in 0.524s
uglify-js 3.10.0
undefined

(nb: the first npx uglifyjs only works when inside a project that has had uglify-js added to the package.json file.)

Robert K. Bell
  • 9,350
  • 2
  • 35
  • 50