React native Android SyntaxError: Attempted to redefine property 'key'

React native Android SyntaxError: Attempted to redefine property 'key'

在 运行 react-native run-android:

之后,我在模拟器(已测试 Genymotion 和 google Stock 模拟器)和物理设备 (Samsung S4) 上收到以下错误

输入的错误: java.util.concurrent.ExcecutionException: java.lang.RuntimeException: SyntaxError: Attempted to redefine property 'key'. (http://192.168.50.37:8081/index.android.bundle?platform=android&dev=true&hot=false:72450)

我是 运行 react native 0.22.2

问题是:key 在某个视图中被定义了两次,例如

<View key={index} key={other} ... />

因此只需删除 key 属性之一。

寻找解决方案的中间步骤:

起初,当在 React Native 菜单中按 Start Chrome Debugging 时,应用程序将再次 运行,但错误会显示在相应浏览器选项卡的控制台中。 然后它显示了更好的错误消息。

奇怪的是 iOS 上没有出现此错误。

我遇到了同样的错误,但关键字不同

在我的例子中,关键字在我的 css styles 属性中声明了两次。

let styles = StyleSheet.create({
    keyword:{}, 
    keyword:{}
});

iOS 上没有崩溃或警告,但在 Android 上导致崩溃。

在 v0.49 上遇到同样的错误。花了很多时间终于发现我的css声明中有重复:

logo: {
    flex:.3,
    height: 120, 
    marginBottom: 10,
},

logo: {
    ...styText,
    marginTop: 10
},

刚刚删除了第二个声明修复了错误。