I'm getting unexpected token '?'
error. But, on debug mode, the error disappears.
3 Answers
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.)
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:
- Delete that example app
- Reset PC
- do the
yarn cache clean
andnpm cache clean -f
And the problem disappears.
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.