Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How create a react app with a specific version using the npx command?

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.

like image 526
Ana S. Avatar asked Feb 22 '26 19:02

Ana S.


2 Answers

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 [email protected] my-app 
like image 164
Stefan van de Vooren Avatar answered Feb 24 '26 09:02

Stefan van de Vooren


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 [email protected] --version
npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected].
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 [ '[email protected]' ] 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 [email protected] uglifyjs --version
npx: installed 1 in 0.631s
uglify-js 3.10.0

$ npx [email protected] --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.)

like image 42
Robert K. Bell Avatar answered Feb 24 '26 10:02

Robert K. Bell



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!