反应本机Android SyntaxError:尝试重新定义属性“键” [英] React native Android SyntaxError: Attempted to redefine property 'key'

查看:130
本文介绍了反应本机Android SyntaxError:尝试重新定义属性“键”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 react-native run-android 后,在模拟器(经过测试的Genymotion和Google Stock Emulator)和物理设备(三星S4)上出现以下错误:

I get the following error on Emulators (tested Genymotion and google Stock Emulator) and on a physical device (Samsung S4) after running react-native run-android:

错误输入:

java.util.concurrent.ExcecutionException:java.lang.RuntimeException:SyntaxError:试图重新定义属性 key。 (http://192.168.50.37:8081/index.android.bundle?platform=android&dev=true&hot=false:72450)


  • 此stackoverflow讨论中 Genymotion发生了类似的错误(也是 java.util.concurrent.ExecutionException ),但那里的解决方案对我没有帮助,即 adb反向tcp:8081 tcp:8081

  • 我还尝试过更改开发设置/ 调试服务器主机&设备的端口 0.0.0.0:8081 ,而不是 MY_IP:8081 ,其中 MY_IP 是我的PC的IP。

  • In this stackoverflow discussion a similar error (also an java.util.concurrent.ExecutionException) occurred with Genymotion but the solution there didn't help me, i.e. adb reverse tcp:8081 tcp:8081.
  • I also tried changing Dev Settings/Debug server host & port for device to 0.0.0.0:8081 instead of MY_IP:8081, where MY_IP is the IP of my PC.

我正在运行本机0.22 .2

I'm running react native 0.22.2

推荐答案

问题是: key 在查看某处,例如

The problem was: key was defined twice in a view somewhere, i.e. something like

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

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

So just remove one of the key properties.

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

Intermediate step to find the solution:

首先,在按下开始时在 React Native菜单中的 Chrome Debugging 中,该应用将再次运行,但错误将显示在相应浏览器选项卡的控制台中。
然后它显示出更好的错误消息。

At first, when pressing Start Chrome Debugging in the React Native Menu, the app will run again, but the error will be shown in the console of the corresponding browser tab. Then it shows a bit better error message.

奇怪的是,此错误在iOS上不会发生。

Strangely this error doesn't occur on iOS.

这篇关于反应本机Android SyntaxError:尝试重新定义属性“键”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆