Error on BarcodeScanner functionality - undefined is not an object evaluating '_ref2.type')

Please provide the following:

  1. SDK Version: 36
  2. Platforms: Android / iOS

I’m having a hard time working with the BarCodeScanner API. I’m seeing this error when running my app on my Huawei P20 Pro, but I’m seeing the exact same error on the emulator from the expo docs themselves: Link to Snack example.

The error message is: undefined is not an object (evaluating '_ref2.type')

This appears to be triggered when trying to set the state using hooks on line 13 of the linked Snack. I’m not sure if this a specific Expo CLI issue, or is related to react-native itself (I’m very new to hooks). Either way, I can’t see how to resolve this; does anyone have any ideas?

On a slightly unrelated note, what is the purpose of line 11 on the linked Snack? It looks like an incomplete line of code?

Thanks guys

EDIT: To further add to this, I thought perhaps the issue was with passing undefined on line 37 of the Snack. So, on my local version, I changed this to null and the error disappeared; changing it back to undefined and the error is still fixed. - This does not resolve the issue on the Snack. I’m now even more confused; I don’t know what I’ve changed…

EDIT2: So, I figured it out. I’m not sure if this is a typo in the docs, or if there’s something else missing. When you specify the function to call onBarCodeScanned, you shouldn’t include the parenthesis (). So changing line 37 on the snack from

onBarCodeScanned={scanned ? undefined : handleBarCodeScanned()}


onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}

resolves the error. I guess this is the right way to do things, because it just worked now; but can anyone confirm why the docs have the parenthesis? Is it a typo? Am I missing something else?

Yes, looks like a typo in the docs when updating it to a functional component and to use SDK 36’s BarCodeScanner.requestPermissionsAsync() instead of Permissions.askAsync(Permissions.CAMERA).

In case you want a comparison, the SDK 35 example still works, even when using SDK 36.

I agree. It looks as if a WIP was used for the example instead of the final working version. I think line 11 was going to be BarCodeScanner.requestPermissionsAsync() and was left in there accidentally.


I’ve submitted a pull request.

Thank you for the reply and submitting the PR. I didn’t know the platform well enough to do that with any confidence. Thank you also for the reference in the PR.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.