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)
- 在 this Whosebug discussion 中,Genymotion 发生了类似的错误(也是
java.util.concurrent.ExecutionException
),但那里的解决方案对我没有帮助,即 adb reverse tcp:8081 tcp:8081
.
- 我还尝试将 Dev Settings/
Debug server host & port for device
更改为 0.0.0.0:8081
而不是 MY_IP:8081
,其中 MY_IP
是我电脑的 IP。
我是 运行 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
},
刚刚删除了第二个声明修复了错误。
在 运行 react-native run-android
:
输入的错误:
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)
- 在 this Whosebug discussion 中,Genymotion 发生了类似的错误(也是
java.util.concurrent.ExecutionException
),但那里的解决方案对我没有帮助,即adb reverse tcp:8081 tcp:8081
. - 我还尝试将 Dev Settings/
Debug server host & port for device
更改为0.0.0.0:8081
而不是MY_IP:8081
,其中MY_IP
是我电脑的 IP。
我是 运行 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
},
刚刚删除了第二个声明修复了错误。