首页 > 解决方案 > undefined 不是一个对象(评估'Component.propTypes') - React Native 0.61.5

问题描述

我已经将现有的 react native 项目从 react native 0.59.6 升级到了 0.61.5。

react-native 升级命令不起作用。所以我已经使用升级助手进行了手动升级。解决了一些帖子问题。现在项目构建成功。

但是从 Xcode 渲染到 ios 模拟器后,它给出了以下错误。

iPhone XR 模拟器截图

我没有在任何地方使用 Component.propTypes。package.lock.json 有一些带有 prop-types 的包。我不确定它到底在做什么。否则,在我的项目中,我也没有使用道具类型。请在下面找到我的 package.lock.json,

包.lock.json

...
...
...

 "prop-types": {
      "version": "15.7.2",
      "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
      "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
      "requires": {
        "loose-envify": "^1.4.0",
        "object-assign": "^4.1.1",
        "react-is": "^16.8.1"
      }
    },
....
"react": {
      "version": "16.9.0",
      "resolved": "https://registry.npmjs.org/react/-/react-16.9.0.tgz",
      "integrity": "sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w==",
      "requires": {
        "loose-envify": "^1.1.0",
        "object-assign": "^4.1.1",
        "prop-types": "^15.6.2"
      }
    },
....

包.json

{
  "name": "wasfat",
  "version": "1.0.3",
  "private": true,
  "rnpm": {
    "assets": [
      "app/assets/fonts/corbel"
    ]
  },
  "scripts": {
    "prepare-repository": "npm i -g react-native-cli yarn;yarn install; react- native link",
    "emulator": "emulator -avd Nexus5V6L23_x86_64 -scale 1.0",
    "clean": "watchman watch-del-all && npm cache clean && cd android && ./gradlew clean && cd ..",
    "test": "jest",
    "postinstall": "rm -rf node_modules/react-native-twitter-signin/node_modules",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "lint": "eslint ."
  },
  "dependencies": {
    "jetifier": "^1.6.5",
    "react": "16.9.0",
    "react-native": "^0.61.5",
    "react-native-actionsheet": "^2.4.2",
    "react-native-android-keyboard-adjust": "^1.2.0",
    "react-native-aws3": "0.0.8",
    "react-native-deep-linking": "^2.2.0",
    "react-native-device-info": "^5.3.1",
    "react-native-double-tap": "^1.0.1",
    "react-native-drawer": "^2.5.1",
    "react-native-elements": "^1.0.0",
    "react-native-exception-handler": "^2.10.8",
    "react-native-fbsdk": "^1.1.0",
    "react-native-firebase": "^5.5.6",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-google-signin": "^1.2.3",
    "react-native-hide-with-keyboard": "^1.2.0",
    "react-native-image-crop-picker": "^0.25.3",
    "react-native-image-picker": "^0.28.1",
    "react-native-image-slider": "^2.0.3",
    "react-native-image-view": "^2.1.5",
    "react-native-keyboard-avoiding-view": "^1.0.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-keyboard-aware-scrollview": "^2.0.0",
    "react-native-keyboard-aware-view": "0.0.14",
    "react-native-keyboard-listener": "^1.1.0",
    "react-native-modal": "^11.1.0",
    "react-native-paper": "^2.15.0",
    "react-native-picker-select": "^6.2.0",
    "react-native-popup-menu": "^0.15.6",
    "react-native-progress": "^3.6.0",
    "react-native-read-more-text": "^1.1.0",
    "react-native-responsive-image": "^2.3.1",
    "react-native-responsive-screen": "^1.2.1",
    "react-native-s3-upload": "0.0.12",
    "react-native-share": "^1.2.1",
    "react-native-side-drawer": "^1.1.9",
    "react-native-side-menu": "^1.1.3",
    "react-native-simple-toast": "0.0.8",
    "react-native-snap-carousel": "^3.8.0",
    "react-native-swiper-flatlist": "^1.0.10",
    "react-native-twitter-signin": "^1.1.1",
    "react-native-vector-icons": "^6.6.0",
    "react-native-video": "^4.4.4",
    "react-native-video-controls": "^2.2.3",
    "react-native-video-player": "^0.10.0",
    "react-native-view-more-text": "^2.1.0",
    "react-navigation": "^3.3.0",
    "react-redux": "^7.1.0",
    "react-spinkit": "^3.0.0",
    "redux": "^4.0.4"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

我发现这个https://reactjs.org/warnings/dont-call-proptypes.html关于这个问题。但我不确定如何使用它。因为按照这个。一些直接使用 propTypes 的第三方库。但是如何处理呢?

0.61 版本 Github 问题没有帮助。请为此问题提出一些解决方法。

谢谢你的帮助。

标签: javascriptiosreact-native

解决方案


推荐阅读