28

My situation is this :

I had a working copy of a react-native project that was working well. Had it commited to my git repository.

I decided to upgrade react-native to 0.26.3 and then 0.28 and finally ended up in a big dependency mess with collisions. So decided to go back to previous working version. Reverted the changes. Removed node_modules folder from my working directory.

But now npm install just won't work.

My working dependencies in package.json

  "dependencies": {
    "immutable": "^3.8.1",
    "key-mirror": "^1.0.1",
    "react": "^15.0.2",
    "react-native": "^0.26.0",
    "react-native-router-flux": "^3.26.1",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-thunk": "^2.1.0",
    "strformat": "0.0.7"
  },
  "devDependencies": {
    "babel-core": "^6.10.4",
    "babel-jest": "^12.1.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react-native": "^1.9.0",
    "babel-register": "^6.9.0",
    "chai": "^3.5.0",
    "fetch-mock": "^4.5.4",
    "jest-cli": "^12.1.1",
    "mocha": "^2.5.3",
    "mockery": "^1.7.0",
    "nock": "^8.0.0",
    "redux-mock-store": "^1.1.1",
    "sinon": "^1.17.4",
    "sinon-chai": "^2.8.0",
    "sinon-stub-promise": "^2.0.0"
  }

Now I get

npm ERR! peerinvalid The package react@15.1.0 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer react-native@0.26.3 wants react@15.0.2
npm ERR! peerinvalid Peer react-redux@4.4.5 wants react@^0.14.0 || ^15.0.0-0

This just not makes sense to me, as my react dependency is 15.0.2 and react-native 0.26.0 as you can see in package.json.

Note that this is from a previous commit that was working (the whole lot). I also did a npm ls. Weirdly wrong dependencies are shown in the tree like wrong versions of react-native, react-native-router-flux, react.

link to ls output

Sathyakumar Seshachalam
  • 2,013
  • 3
  • 20
  • 32

8 Answers8

27

For existing projects if you want to install/downgrade to lower version

npm install react-native@x.x.x  ex: npm install react-native@0.43.4

This will install the version specified.

Check the installed version with react-native --version

liamnickell
  • 166
  • 1
  • 12
chetan
  • 953
  • 3
  • 12
  • 20
11

Update 2020

Just run

npm install react-native@0.43.8

Replace 0.43.8 with version you need.

Saranjith
  • 11,242
  • 5
  • 69
  • 122
10

Please update your react dependency in package.json to explicitly be 15.0.2, not ^15.0.2 since the latter resolves to 15.1.0 which causes this issue. It is recommended to leave it that way until you upgrade for the next time and get this error once again (to avoid react changing its version in the meantime and react-native not being ready for it).

Also, with npm3 EPEERINVALID is no longer an error, but warning.

Mike Grabowski
  • 1,955
  • 16
  • 17
5

Downgrading React Native requires manual steps. I recommend using https://react-native-community.github.io/upgrade-helper/ and here are my steps

  1. Set your current version as base and select the previous minor version of react-native
  2. Revert all the changes made to files as displayed in the compare view in step 1
  3. Delete node_modules folder, clear watchman, reset metro cache, delete pods, clear ios and android cached files. npx react-native-clean-project is super helpful.
  4. yarn or npm install and reinstall pods for ios
  5. Make sure all your jest tests, detox tests and manually testing both iOS and Android are working as expected.
  6. (if needed) Repeat the steps to downgrade to another lower version

Suggestion: If you're downgrading multiple minor versions then it might be easier to downgrade one version at a time. For example, downgrading from 0.61.x to 0.58.x, would be less work to downgrade to version 0.60.x first, test and make sure everything works in iOS and Android then move on

Guy
  • 2,883
  • 1
  • 32
  • 39
  • Thanks for this. Do you know if it's necessary to update project.pbxproj by hand? Or does updating all the other files cause project.pbxproj to get updated automatically? – gkeenley Apr 10 '20 at 02:38
  • 1
    @gkeenley You have to update project.pbxproj by hand unfortunately – Guy Apr 10 '20 at 02:41
  • Ok thanks. Do you know generally what type of changes cause project.pbxproj to update automatically, and which ones don't? – gkeenley Apr 10 '20 at 03:12
  • 1
    The things that I know are: using Xcode and applying their recommended updates. using react-native upgrade or any command line tools that help upgrading react-native projects. – Guy Apr 10 '20 at 15:14
  • Those are the ones that do update it automatically? – gkeenley Apr 10 '20 at 15:21
  • 1
    As far as I know, yes. – Guy Apr 10 '20 at 20:40
  • 1
    Sorry I thought I had. Done now :) – gkeenley Apr 13 '20 at 17:31
2

Try npm prune and then npm i again.

The command npm prune will basically remove all unwanted packages, and npm i will make sure all missing packages are installed.

joe
  • 2,468
  • 2
  • 12
  • 19
Rohit Shedage
  • 23,944
  • 1
  • 13
  • 18
1

I tried to downgrade from react-native 0.71.1 to 0.70.4 with just npm i react-native@0.70.4 and fix whatever errors came up. In my case I needed this because the package react-native-vision-camera was not yet compatible with react-native 0.71.1.

But I had dozens of errors, which after a while I started to understand are due to the fact that the whole android folder that is being set up from a template when you run the npx react-native init script, has differences and must match the react-native package version. So I guess if you downgrade a minor version in this way, not just a patch, you are just very lucky if it works somehow. I would not do it.

I instead decided to freshly init react-native with the desired version:

  • Just git commit all your changes and push them to the remote (to be safe), mv your current project folder to a different name.

  • Run npx react-native init <YourProjectName> --version 0.70.6 to get the desired version, but make sure to use the same ProjectName, otherwise you might have configuration mismatches.

  • Integrate your own code from the old project folder (if you forget something git will tell you later), merge configuration files, etc.

  • add packages by running npm install <package-name> <package-2-name> <etc.) and npm install -D (for devDependencies). Don't copy the dependencies / devDependencies over from package.json, as that way you'll probably not get the right package versions that match your versions of react, react-native etc.

  • finally copy .git folder from your old project folder into the new one, and check the changes, to make sure you did not forget anything. And then you will actually see all the differences in the template I mentioned above. In my case more than 30 files were different between those minor versions.

Wu Wei
  • 1,827
  • 1
  • 15
  • 27
0

If you're using react-native you can modify your package.json file with the versions that you need and then delete all your node modules rm -rf node_modules and then reinstall npm install

David Vittori
  • 1,146
  • 1
  • 13
  • 30
0

If you change the version in Package.json and reinstall npm packages it will make build errors. Please refer and downgrade/upgrade to a specific version.

Agilanbu
  • 2,747
  • 2
  • 28
  • 33
Srinath
  • 88
  • 7