转地址: https://www.jianshu.com/p/255720219e99
所遇到的错误
- Cannot add a child that doesn't have a YogaNode to a parent without a measure function!
(Trying to add a 'ReactRawTextShadowNode' to a 'LayoutShadowNode')
代码如下
App.js
export default class App extends Component<{}> {
render() {
if (Platform.OS === 'android') {
return <ViewTest style={{flex:1}}/>
}
}
}
// ViewTest.js
export default class ViewTest extends Component{
render(){
return (
<View style={[styles.container,styles.flex]}>
<View style={styles.item}>
// 第1列
<View style={[styles.flex,styles.center]}>
<Text style={styles.textStyle}>酒店</Text>
</View>
</View>
</View>
)
};
}
问题原因及解决方案: //
这不是 ReactNative 在 JSX 中的注释方式,注释方式为 {/**/}
,更改注释后就好了。
- Navigator 使用错误。
这两天在使用Navigator
时一直报错。
错误一:
Invariant Violation: Navigator is deprecated and has been removed from this package.
It can now be installed and imported from `react-native-deprecated-custom-components` instead of `react-native`.
Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html

错误原因及解决方案:
错误原因是因为 React Native
在 0.44 以后已经把 Navigator
废弃掉了,不能使用 import {Navigator} from 'react-native';
进行导入了。根据提示需要导入 react-native-deprecated-custom-components
解决步骤:
1.进入到项目的根目录下。
2.使用命令行 :npm install react-native-deprecated-custom-components --save
3.在使用Navigator的地方引用。引用方式:import {Navigator} from "react-native-deprecated-custom-components"
注意:在引用时 一定在导入 Navigator的时候加上 {}
要不然会报错。
安装如果出错的解决:
方案一:使用命令:npm i react-native-deprecated-custom-components --save
如果此方法还不能解决。
方案二:使用yarn
命令(前提是自己有yarn
的配置环境)yarn add react-native-deprecated-custom-components --save
。
Navigator 错误二:
我在上述引用 react-native-deprecated-custom-components
后,使用 Navigator 还是会报错。
错误提示: Cannot read property 'shape' of undefined
作者:王菜花丶
链接:https://www.jianshu.com/p/255720219e99
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

错误还是因为 React Native
在 0.44 以后已经把 Navigator
废弃掉了。
现在要改为用 React Navigation
。详情请参考github react-native, React Native 使用文档,新手理解Navigator的教程
PS : 这个错误卡了我两天啊。。。
3.PropTypes 错误
Cannot read property 'string' of undefined
作者:王菜花丶
链接:https://www.jianshu.com/p/255720219e99
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

PropTypes
时导入出错。
import React, {Component,PropTypes} from 'react';
原因是 :
React v15.5
起就被移除了,需要改用
prop-types
库代替。
解决方案:
- 进入项目根目录,安装 prop-types 库:
npm install --save prop-types
- 引入:
import PropTypes from 'prop-types';