React-Native 遇到的错误

1. React-Native 部分组件在debug模式下打包在iOS真机上可以显示,但是release模式下打包在iOS真机上不显示

React-Native 遇到的错误_第1张图片
显示
React-Native 遇到的错误_第2张图片
不显示

这个问题真的是卡了我好久,只要是打release包,下面的按钮组就是不显示,而release包又不能调试,于是我终于在忍无可忍的情况下,一直不能打包然后一点一点的展示在页面上,来看到底是哪里的问题。终于让我定位到了问题的所在。

问题出在这:

let buttons = [];
children.forEach((child, i) => {
      if (child.type.name === 'FlowSendButton') {
        const buttonConfig = FlowSendButton({
          setShowWriteNotion: this.setShowWriteNotion,
          requireNotion: child.props.requireNotion,
          ...child.props,
        });
        if (this.getShow(child.props)) {
          buttons.push(buttonConfig);
        }
      } else if (child.type.name === 'FlowNotionButton') {...}
...
});

这段代码在release包的情况是,buttons是空的,是由于if (child.type.name === 'FlowSendButton')这是判断根本不会为true,因为在release模式下,child.type根本没有name这个属性,只有在debug模式下才有,所以这样来进行判断的 ,统统不会有true的情况,自然buttons中没有值,也就不会展示了。

下面是我找到的一些文档中的交流:

  • stackoverflow中的一个相关问题
判断方式 release debug
if (child.type.displayName === 'FlowCancelDoButton') {} 失效 有效
if (child.type.name === 'FlowCancelDoButton') {} 失效 有效
if (child.type.prototype instanceof FlowCancelDoButton) {} 失效 有效
if (child.type === FlowApproveButton) {} 有效 有效

判断方式一览表

判断方式 release debug
if (child.type.displayName === 'FlowCancelDoButton') {} 失效 有效
if (child.type.name === 'FlowCancelDoButton') {} 失效 有效
if (child.type.prototype instanceof FlowCancelDoButton) {} 失效 有效
if (child.type === FlowApproveButton) {} 有效 有效

总结

2. React-Native 启动时报错 - “no bundle url present”

原因

我运行了react-native run-android看了一下安卓环境下的图标的样式,然后使用react-native run-ios就报错了no bundle url present这个错误,我什么都没有干啊。

React-Native 遇到的错误_第3张图片
error

图片上的错误就不停,度娘了一下,原来是,因为我开了两个环境吧,可是我把环境都关了,还是不行。

解决

于是我就在iOS模拟器正在运行期间执行了:

npm install
react-native run-ios

zz,一遍还不行,试了两遍才正常了!!!


若干天后,又遇到了这个问题,按照上面的方式试了好多次都不行,只能关机重启,就好了。~~~(>_<)~~~
zz

RawText "/*" must be wrapped in an explicit component错误

是因为{test}中的test被这是为了空字符串'',就会报这个错,要保证test不会被设置为''.

ReactNative js调试时变得很卡

解决办法

把那个chrome的Tab页保持最前,窗口不要最小化就好了。也就是下面这个页面不要关,保持在最前面就好了。

React-Native 遇到的错误_第4张图片
js slow.png

一直报[...effects] has been deprecated in favor of all([...effects]), please update your code这个警告。

解决办法

只需要这样更新代码即可。

React-Native 遇到的错误_第5张图片
fix.png

你可能感兴趣的:(React-Native 遇到的错误)