How to create specify typescript RN version?

Viewed 2179

I type the command to create React Native project with typescript.

npx react-native init MyApp --template react-native-template-typescript

package.json

"react-native": "0.63.2"

I want to create 0.62.2 with typescript so I try the command:

npx react-native init MyApp --version 0.62.2 --template react-native-template-typescript

package.json

"react-native": "0.63.0"

It is 0.63.0 not 0.62.2

Why I can't create 0.62.2 with typescript ?

3 Answers

For typescript template, the version of react native depends on the react-native-template-typescript version, for example:

  • react-native-template-typescript@6.5.9 --> react-native@0.63.4
  • react-native-template-typescript@6.5.7 --> react-native@0.63.3

Therefore if you want to install version react-native@0.63.4, you need to apply the command like this:

npx react-native init AwesomeTSProject --template react-native-template-typescript@6.5.9

more info: react-native-template-typescript releases

Okay, I just spent a bunch of time trying to get it to work myself, and this is what worked:

npx react-native init MyApp --template react-native-template-typescript@6.4.* --version 0.62.2

Note the specific version of the template package. To find the right template version for other versions of React Native, see https://github.com/react-native-community/react-native-template-typescript#usage-with-older-versions-of-react-native.

If a wrong version is still getting installed, it's most likely you have another version of react-native installed globally. Run npm uninstall -g react-native react-native-cli @react-native-community/cli (whatever you installed previously), and make sure which react-native returns an empty result.


Previous incorrect answer:

I believe the correct syntax for having npx run a specific package version is:

npx react-native@0.62.2 init MyApp --template react-native-template-typescript

Alternatively, you can instead install a specific version of react-native on your machine using npm i -g react-native@0.62.2 and then run react-native init MyApp --template react-native-template-typescript (without npx).

Try please,

npx react-native init MyApp --version react-native@0.62.2 --template react-native-template-typescript
Related