Javascript 降级 react-native 的正确机制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38024203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:59:51  来源:igfitidea点击:

Proper mechanism to downgrade react-native

javascriptnode.jsnpmreact-native

提问by Sathyakumar Seshachalam

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.

我有一个运行良好的 react-native 项目的工作副本。如果它已提交到我的 git 存储库。

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.

我决定将 react-native 升级到 0.26.3,然后升级到 0.28,最终导致了严重的依赖冲突和冲突。所以决定回到以前的工作版本。恢复了更改。从我的工作目录中删除了 node_modules 文件夹。

But now npm installjust won't work.

但现在npm install就是行不通。

My working dependencies in package.json

我在 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 [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants [email protected]
npm ERR! peerinvalid Peer [email protected] 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.

这对我来说没有意义,因为我的 react 依赖项是 15.0.2,而 react-native 是 0.26.0,正如你在 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.

请注意,这是来自之前正在工作的提交(全部)。我也做了一个npm ls. 树中显示了奇怪的错误依赖项,例如react-native, react-native-router-flux, 的错误版本react

link to ls output

链接到 ls 输出

采纳答案by Mike Grabowski

Please update your reactdependency in package.json to explicitly be 15.0.2, not ^15.0.2since the latter resolves to 15.1.0which 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 reactchanging its version in the meantime and react-nativenot being ready for it).

请将reactpackage.json 中的依赖项显式更新为15.0.2,而不是^15.0.2因为后者解决了15.1.0导致此问题的原因。建议保持这种状态,直到您下次升级并再次出现此错误(以避免react在此期间更改其版本而react-native没有准备好)。

Also, with npm3 EPEERINVALIDis no longer an error, but warning.

此外,使用 npm3EPEERINVALID不再是错误,而是警告。

回答by chetan

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

对于现有项目,如果您想安装/降级到较低版本

npm install [email protected]  ex: npm install [email protected]

This will install the version specified.

这将安装指定的版本。

Check the installed version react-native -version

检查安装的版本 react-native -version

回答by Saranjith

Update 2020

2020 年更新

Just run

赶紧跑

npm install [email protected]

Replace 0.43.8with version you need.

替换0.43.8为您需要的版本。

回答by Guy

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

降级 React Native 需要手动步骤。我建议使用https://react-native-community.github.io/upgrade-helper/。这是我的步骤

  1. Set your current version as base and select the previous minor release of react-native (You should downgrade one version at a time, it's not very easy to downgrade from 0.61.x to 0.59.x or lower using this method)
  2. Revert all the changes made to files as displayed in the compare view
  3. Delete node_modules folder, clear watchman, reset metro cache, Clear ios cached files and Android cached file.
  4. yarnor npm install
  5. Test that both iOS and Android version are working
  6. (if needed) Repeat the steps to downgrade to another lower version
  1. 将当前版本设置为 base 并选择 react-native 之前的小版本(你应该一次降级一个版本,使用这种方法从 0.61.x 降级到 0.59.x 或更低不是很容易)
  2. 恢复对比较视图中显示的文件所做的所有更改
  3. 删除 node_modules 文件夹,清除 watchman,重置 Metro 缓存,清除 ios 缓存文件和 Android 缓存文件。
  4. yarn或者 npm install
  5. 测试 iOS 和 Android 版本是否正常工作
  6. (如果需要)重复步骤以降级到另一个较低版本

Important: If you're downgrading multiple versions then you should downgrade one version at a time. For example, downgrading from 0.61.x to 0.58.x, should towngrade to version 0.60.x first, test that it works in iOS and Android then move on and downgrade to version 0.59.x

重要提示:如果您要降级多个版本,则应一次降级一个版本。例如,从 0.61.x 降级到 0.58.x,应该先towngrade 到 0.60.x 版本,测试它在 iOS 和 Android 上是否有效,然后继续并降级到 0.59.x 版本

回答by Rohit Shedage

Try npm pruneand then npm iagain.

尝试npm prunenpm i一次。

The command npm prunewill basically remove all unwanted packages, and npm iwill make sure all missing packages are installed.

该命令npm prune将基本上删除所有不需要的包,并npm i确保安装所有丢失的包。

回答by David Vittori

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

如果您使用的是 react-native,您可以使用您需要的版本修改 package.json 文件,然后删除所有节点模块 rm -rf node_modules 然后重新安装 npm install

回答by Srinath

If you change the version in Package.jsonand reinstall npm packagesit will make build errors. Please referand downgrade/upgradeto a specificversion.

如果您更改版本Package.json并重新安装npm packages它会导致构建错误。请参考降级/升级特定版本。