score:6

Accepted answer

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 

score:0

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.)


Related Query

More Query from same tag