【问题标题】:Invariant Violation: ViewPropTypes has been removed from React Native不变违规:ViewPropTypes 已从 React Native 中移除
【发布时间】:2023-01-25 23:07:29
【问题描述】:

请任何人帮助我如何解决此错误“错误不变违规:ViewPropTypes 已从 React Native 中删除。迁移到从'deprecated-react-native-prop-types'导出的 ViewPropTypes。” 我已经尝试了很多事情,比如删除节点模块 npm install deprecated-react-native-prop-types 但对我没有任何作用我现在该如何修复

包.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/bottom-tabs": "^5.11.10",
    "@react-navigation/compat": "^5.3.20",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "deprecated-react-native-prop-types": "^2.3.0",
    "expo": "^46.0.0",
    "expo-av": "~12.0.4",
    "expo-linear-gradient": "~11.4.0",
    "expo-status-bar": "~1.4.0",
    "haversine": "^1.1.1",
    "invariant": "^2.2.4",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native": "0.69.5",
    "react-native-animatable": "^1.3.3",
    "react-native-flexi-radio-button": "^0.2.2",
    "react-native-fontawesome": "^7.0.0",
    "react-native-gesture-handler": "~2.5.0",
    "react-native-modal": "^13.0.0",
    "react-native-modalize": "^2.0.8",
    "react-native-progress-circle": "^2.1.0",
    "react-native-reanimated": "~2.9.1",
    "react-native-safe-area-context": "4.3.1",
    "react-native-screens": "~3.15.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-swiper": "^1.6.0",
    "react-native-web": "~0.18.7",
    "react-navigation": "^4.4.4",
    "rn-sliding-up-panel": "^2.4.5"
  },
  "devDependencies": {
    "@babel/core": "^7.18.6"
  },
  "private": true
}

babel.config.js

module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: ['react-native-reanimated/plugin'], };

【问题讨论】:

  • 这是由于未更新的库,你需要删除它们或自己更新它们......顺便说一句,这只是 react-native 0.69 及更高版本的错误,因此你也可以降级你的项目 react-native 版本。
  • @lmasneri 它的解决方案是什么,请逐步告诉解决方案
  • 解决方案是找到已弃用的库,在错误中提到了错误所在。另一个解决方案是使用 react-native upgrade helper (react-native-community.github.io/upgrade-helper) 降级到 react-native 0.68.3
  • @lmasneri 不工作我试过了
  • 没有任何 3rd 方库它仍然不起作用?

标签: javascript reactjs react-native expo


【解决方案1】:

您将需要检查包含以下导入语句的 node_modules 文件夹中所有已下载的依赖项。

import { ViewPropTypes } from 'react-native';

更改它手动从 deprecated-react-native-prop-types 导入。

import { ViewPropTypes } from 'deprecated-react-native-prop-types';

【讨论】:

  • 同样的错误我已经从'react-native'中删除了import {ViewPropTypes};在我的每个文件中导入 { ViewPropTypes } from 'deprecated-react-native-prop-types';
  • 您可以尝试在命令提示符下键入以下命令来清除缓存。 cd android && gradlew clean
  • 有关更多信息,您可以尝试阅读此处的帖子。 github.com/facebook/react-native/issues/…
  • 这是一个 expo 应用程序,我不能 cd android
  • 由于我不熟悉 expo,您可能会找到类似 this 的内容并尝试。
【解决方案2】:

除了 kiuQ 的回答,react-native-progress-circle 很可能是这里的问题。它已被弃用,并且 ViewPropTypes 是该包中的一个已知问题。

从你的项目中删除它,或者简单地用https://www.npmjs.com/package/progress-circle-react-native替换它

【讨论】:

    猜你喜欢
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2022-06-10
    • 2022-08-24
    • 1970-01-01
    • 2018-10-04
    • 2018-07-07
    相关资源
    最近更新 更多