63

I am trying to create a new react native project which should utilize an older version of react-native.

The result I would like would be to do something like: react-native init MyProject but have the version of react-native it uses be 0.13.2.

However, there doesn't seem to be any options with react-native-cli for initializing with old versions of react-native.

Performing react-native init MyProject and then dowgrading react-native in package.json also does not work because the init command installs a bunch of xcode templates which are used to build the app and there is no dowgrade command which will dowgrade these templates. (There is an upgrade command.)

I tried downgrading my version of react-native-cli to 0.1.4 which was current when react-native 0.13 was current, but this did not work. From looking at the cli source, it seems it always initializes with just the newest version of react-native.

I realize this is pretty weird to want to start a new project at an old version, but I have a weird set of requirements that are forcing this.

Jordan Ell
  • 1,745
  • 3
  • 16
  • 24
  • 4
    AFAIK, I couldn't find some kind of 'downgrade of react-native'. But when you init a project, `$ react-native init ProjectName --version 0.39.0` ref: https://github.com/facebook/react-native/blob/master/react-native-cli/index.js#L51 – roy Jan 05 '17 at 08:12

10 Answers10

68

There is a new parameter in react-native init that allows just this. Try:

react-native init --version="react-native@0.36.0" MyNewApp

Here my source. I have successfully tested it with react-native-cli 2.0.1.

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
martinarroyo
  • 9,389
  • 3
  • 38
  • 75
38

rninit is a replacement for react-native init that allows you to specify a particular version of react-native to use.

Install rninit globally:

npm install -g rninit

Specify which version of react-native to use:

rninit init [Project Name] --source react-native@0.14.2

Thanks to @vanson-wing-leung for pointing me to rninit

emmby
  • 99,783
  • 65
  • 191
  • 249
27

Use the --version flag.

react-native init blank --version react-native@0.14.2
Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
Benjamin J. Benoudis
  • 1,101
  • 11
  • 22
6

Here's the command as of April 2022.

npx react-native init newproject --version="0.66.4"

codejays
  • 713
  • 6
  • 9
2

Try this:

If you install the version of react-native that you want in your project, you can then navigate to (project)/node_modules/react-native/local-cli. Here you will see three generator folders which enclose the exact files RN would have used to initiate a project.

It's a bit manual, but at least you'll have access to the original files.

John Shammas
  • 2,687
  • 1
  • 17
  • 33
  • This is a good start, thanks! I have formally submitted an issue to react native asking for native support of this feature. https://github.com/facebook/react-native/issues/4723 – Jordan Ell Dec 10 '15 at 23:46
2

specify react-native version at the time of installing

something like this

react-native init --version="react-native@0.52.0" ExampleApp
omkar yadav
  • 177
  • 5
  • 15
1

The only solution that works with react native latest cli is

react-native init NewProject --version X.XX.X 

e.g

react-native init NewProject --version 0.61.5 

Thanks @Shamendra

Sumanta
  • 1,165
  • 4
  • 15
  • 25
0

react-native init MyApp --version react-native@0.58.6

Ashutosh Dash
  • 602
  • 2
  • 7
  • 15
0

To use the same version of CLI to install React Native, you can use:

npx react-native@0.60.0 init rn60 --version="0.60.0"

output:

Need to install the following packages:
  react-native@0.60.0
Ok to proceed? (y)


               ######                ######
             ###     ####        ####     ###
            ##          ###    ###          ##
            ##             ####             ##
            ##             ####             ##
            ##           ##    ##           ##
            ##         ###      ###         ##
             ##  ########################  ##
          ######    ###            ###    ######
      ###     ##    ##              ##    ##     ###
   ###         ## ###      ####      ### ##         ###
  ##           ####      ########      ####           ##
 ##             ###     ##########     ###             ##
  ##           ####      ########      ####           ##
   ###         ## ###      ####      ### ##         ###
      ###     ##    ##              ##    ##     ###
          ######    ###            ###    ######
             ##  ########################  ##
            ##         ###      ###         ##
            ##           ##    ##           ##
            ##             ####             ##
            ##             ####             ##
            ##          ###    ###          ##
             ###     ####        ####     ###
               ######                ######


                  Welcome to React Native!
                 Learn once, write anywhere.

✔ Downloading template
✔ Copying template
✔ Processing template
✔ Installing dependencies
✔ Installing CocoaPods dependencies (this may take a few minutes)

  Run instructions for iOS:
    • cd rn60 && react-native run-ios
    - or -
    • Open rn60/ios/rn60.xcworkspace in Xcode or run "xed -b ios"
    • Hit the Run button

  Run instructions for Android:
    • Have an Android emulator running (quickest way to get started), or a device connected.
    • cd rn60 && react-native run-android

test

$ cd rn60
$ cat package.json
{
  "name": "rn60",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.8.6",
    "react-native": "0.60.0" <----
  },
  "devDependencies": {
    "@babel/core": "^7.3.3",
    "@babel/runtime": "^7.3.1",
    "@react-native-community/eslint-config": "^0.0.3",
    "babel-jest": "^24.1.0",
    "jest": "^24.1.0",
    "metro-react-native-babel-preset": "^0.54.1",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}
Gianfranco P.
  • 10,049
  • 6
  • 51
  • 68
-1

For existing react native project to downgrade run

npm install react-native@0.13.2

Then verify the version by running

react-native -version
hzak
  • 719
  • 9
  • 18