React Native Vision Camera UseCodeScanner Error Exception

387 Views Asked by At

I have an issue with the "useCodeScanner".

**ERROR **TypeError: 0, _$$_REQUIRE(_dependencyMap[11(...)e-vision-camera").useCodeScanner is not a function (it is undefined)

This error is located at: in Home (created by SceneView)
in StaticContainer in EnsureSingleNavigator (created by SceneView) in SceneView (created by SceneView)
in RCTView (created by View) in View (created by DebugContainer)
in DebugContainer (created by MaybeNestedStack) in MaybeNestedStack (created by SceneView) in RCTView (created by View) in View (created by SceneView)
in RNSScreen in Unknown (created by InnerScreen)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by InnerScreen) in InnerScreen (created by Screen)
in Screen (created by SceneView)
in SceneView (created by NativeStackViewInner) in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by ScreenStack) in RNSScreenStack (created by ScreenStack) in ScreenStack (created by NativeStackViewInner) in NativeStackViewInner (created by NativeStackView) in RNCSafeAreaProvider (created by SafeAreaProvider) in SafeAreaProvider (created by SafeAreaInsetsContext) in SafeAreaProviderCompat (created by NativeStackView) in NativeStackView (created by NativeStackNavigator) in PreventRemoveProvider (created by NavigationContent) in NavigationContent in Unknown (created by NativeStackNavigator) in NativeStackNavigator (created by App) in EnsureSingleNavigator in BaseNavigationContainer in ThemeProvider in NavigationContainerInner (created by App) in Appyour text in RCTView (created by View) in View (created by AppContainer)
in RCTView (created by View) in View (created by AppContainer)
in AppContainer in ScanEat(RootComponent), js engine: hermes Do you have any ideas on how to fix it? I really appreciate any help you can provide .

 import {
  Camera,
  useCameraDevices,
  useCodeScanner,
} from 'react-native-vision-camera';
const devices = useCameraDevices();
  const device = devices.back;

  useEffect(() => {
    checkPermission();
  }, []);

  const checkPermission = async () => {
    try {
      const newCameraPermission = await Camera.requestCameraPermission();
      console.log('Camera Permission:', newCameraPermission);
    } catch (error) {
      console.error('Camera Permission Error:', error);
    }
  };

  
const codeScanner = useCodeScanner({
  codeTypes: ['qr', 'ean-13'],
  onCodeScanned: (codes) => {
    console.log(`Scanned ${codes.length} codes!`)
  }
})

  if (device == null) {
    return (
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
        <ActivityIndicator />
      </View>
    );
  }  return (
    <SafeAreaView
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#000',
      }}>
      <Camera
        style={StyleSheet.absoluteFill}
        device={device}
        isActive={true}
        codeScanner={codeScanner}
      />
  
    </SafeAreaView>
  );
0

There are 0 best solutions below