5

I'm getting unexpected token '?' error. But, on debug mode, the error disappears.

enter image description here

3 Answers 3

3

I was having this exact problem, but only in Android. The problem was caused by my use of a nullish coalescing assignment operator (??=). For example, something like:

obj ??= {};

React Native doesn't support this operator. Therefore, look for all occurrences of ??= in your code and try changing it to the extended way; e.g.:

if(obj == undefined)
   obj = {};

You must avoid using this operator until React Native adds support for it.

(I'm not sure, but the nullish coalescing operator (??) may lead to the same problem, so you may wish to avoid it, too.)

0
1

In my case, this issue happened to me after I installed an example app with:

"metro-config": "^0.72.1" and "react-native": "0.70.0-rc.4".

While my main app was still using "react-native": "0.66.4"

It also replicated when I reverted the code. So I came up with this solution:

  1. Delete that example app
  2. Reset PC
  3. do the yarn cache clean and npm cache clean -f

And the problem disappears.

0

My problem was just because I was importing an empty json file without even a bracket {}. So refering to the first answer above it was a undefined json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.