CRNA、genymotion、expo 奇怪的错误

CRNA, genymotion, expo weird error

我正在使用 genymotion 运行 我的 React Native 开发环境。当加载特定组件时,我收到 console.error 消息:there was a problem sending log messages to your development environment 带有奇怪的堆栈跟踪,使用 <unknown> 代替几个命名函数。

我将问题缩小到代码中的一个组件:

class Questions extends React.Component {
  constructor(props){
    super(props);
    this.state = {
                  style: 'all',
                  selected: ''}
  }
  render = () => {
    return (
      <View style={styles.questions}>
        <ScrollView>
          {(this.props.questions && this.state.style == 'all')&&
            this.props.questions.map(post => {
              return (
                <TouchableHighlight onPress={() => this.loadQuestion(post)} key={post.ID + new Date(post.post_date)} style={styles.questionCard} >
                  <View style={styles.questionCard} >
                    <View style={styles.title}>
                      <Text style={{color: 'white'}}>{post.post_title}</Text>
                      <Text style={{color: 'white'}}> - {post.display_name} {utils.timeSince(new Date(post.post_date))}</Text>
                    </View>
                  </View>
                </TouchableHighlight>
              )
            })
          }
        </ScrollView>
      </View>
    )
  }
}

每当加载此组件时,我都会得到上面提到的 console.error。我知道这没什么好继续的,我什至不期待答案,但我不知所措。

如果你 google 那个确切的错误消息你会在 Github 上找到一个没有解决的问题,提到它可能是 expo sdk 中的一个错误(这是有道理的)并链接另一个发出 404s.

好的,我想我已经解决了,问题实际上出在我的 utils 函数中 timeSince。我有一个杂散的 console.log() 语句,当我删除它时,错误消失了。显然,使用此配置,您无法从内部资产调用 console.log()。

编辑:好的,在进一步调试之后,当您尝试 console.log() 一个对象时会抛出此错误,日志的来源无关紧要。

Okay I think I solved it, the problem was actually in my utils function timeSince. I had a stray console.log() statement and when I removed it the error went away. Apparently with this configuration you cannot call console.log() from internal assets.

EDIT: Okay so after some further debugging, this error is thrown when you try to console.log() an object, it doesn't matter where the log originates.

我希望这能进一步说明这个“错误”的来源:

你指的对象实际上是调用的响应,它不喜欢它的大小。它不是任何对象,只是调用中的 response 对象。如果你尝试解构你想要的部分,它就会消失