React native Android SyntaxError: Attempted to red

2020-04-06 06:55发布

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:

enter image description here

The error typed out: 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)

  • 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.

I'm running react native 0.22.2

3条回答
神经病院院长
2楼-- · 2020-04-06 07:34

Encountered the same error on v0.49. Spent a lot of time and finally found that there are duplicates in my css declaration:

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

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

just removed the second declaration fixed the error.

查看更多
我只想做你的唯一
3楼-- · 2020-04-06 07:35

I had the same error but with a different keyword

In my case the keyword was declared twice in my css styles properties.

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

No crash or warning on iOS but causing a crash on Android.

查看更多
家丑人穷心不美
4楼-- · 2020-04-06 07:40

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:

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.

Strangely this error doesn't occur on iOS.

查看更多
登录 后发表回答