我最近升级了react-native
"react-native": "^0.50.4",
并做出反应
"react": "^16.2.0",
我还在使用mapbox以及FBSDK,React-Native-Router-Flux等,我收到以下错误
undefined is not an object (evaluating '_react2.PropTypes.string')
我的package.json
如下:
{
"name": "clustr",
"version": "0.9.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"remotedev": "remotedev --hostname=localhost --port=8000",
"flow": "flow"
},
"dependencies": {
"@mapbox/react-native-mapbox-gl": "^6.0.1",
"fuzzysearch": "^1.0.3",
"haversine": "^1.1.0",
"lodash": "^4.17.4",
"moment": "^2.19.3",
"moment-business": "^3.0.1",
"prop-types": "^15.6.0",
"querystring": "^0.2.0",
"react": "^16.2.0",
"react-native": "^0.50.4",
"react-native-branch": "^2.1.1",
"react-native-camera": "^0.10.0",
"react-native-device-info": "^0.10.2",
"react-native-drawer-layout": "^1.3.0",
"react-native-fbsdk": "^0.6.3",
"react-native-geocoder": "^0.4.8",
"react-native-hyperlink": "0.0.10",
"react-native-i18n": "^1.0.0",
"react-native-loading-spinner-overlay": "^0.5.2",
"react-native-maps": "^0.17.1",
"react-native-modalbox": "^1.3.8",
"react-native-page-control": "^1.1.1",
"react-native-qrcode": "^0.2.6",
"react-native-qrcode-scanner": "0.0.22",
"react-native-radio-buttons": "^0.14.0",
"react-native-router-flux": "3.38.0",
"react-native-swipe-gestures": "^1.0.2",
"react-native-vector-icons": "^4.4.2",
"react-redux": "^5.0.4",
"redux": "^3.6.0",
"redux-form": "^6.6.3",
"redux-form-material-ui": "^4.3.1",
"redux-saga": "^0.15.3",
"remote-redux-devtools": "^0.5.7",
"tipsi-stripe": "^3.9.1",
"url-parse": "^1.1.9"
},
"devDependencies": {
"babel-plugin-module-resolver": "^2.7.0",
"flow-bin": "^0.45.0",
"remotedev-server": "0.2.2"
},
"assets": [
"./assets/fonts"
]
}
升级后我换成使用prop-types
,如下所示:
import React from 'react';
import Text from '../generic/CText';
import {Platform, TouchableOpacity, View, Image} from 'react-native';
import PropTypes from 'prop-types';
TitleBar.propTypes = {
title: PropTypes.string
};
export default TitleBar;
依此类推,这在我的所有组件中都是一致的。
非常感谢你的帮助!
答案 0 :(得分:1)
使用react-codemon,在项目目录中运行
jscodeshift -t react-codemod / transforms / React-PropTypes-to-prop-types.js myapp /
这将解决更新源代码和任何节点模块的proptypes。
重新安装节点模块将需要再次运行命令。
请按照https://github.com/reactjs/react-codemod上的说明进行操作,但基本上在安装了jscodeshift之后,您已经下载了react-codemod文件,用于各种命令,例如将React.propTypes转换为PropTypes等等。
myapp / here对应于我的整个应用程序项目目录,因此整个react-native项目。
其次,考虑您正在使用的项目依赖项。例如,在我的情况下,我在版本0.38.0使用react-native-router-flux,该应用程序将在调试模式下工作,但在发布时崩溃。我试图升级到4.0.0-beta.24的最新测试版,问题得到了解决。