rodgomesc / vision-camera-code-scanner

VisionCamera Frame Processor Plugin to read barcodes using MLKit Vision QrCode Scanning
MIT License
337 stars 222 forks source link

iOS - worklet error , Android - undefined error #35

Open whtjs opened 2 years ago

whtjs commented 2 years ago

Hi guys i was heading some issue with iOS and Android both.

Android:

Frame Processor threw an error: undefined is not a function 

iOS:

Error: Javascript worklet error
    at _f (native)

Error: Exception in HostFunction: Javascript worklet error
...

i fixed it by directly using __scanCodes

here is example code that fully works for me

Solution

export const Scanner: React.FC = () => {
  const devices = useCameraDevices();
  const device = devices.back;

  const frameProcessor = useFrameProcessor(frame => {
    'worklet';
    const barcodes = __scanCodes(frame, [BarcodeFormat.ALL_FORMATS]);
  }, []);

  if (device == null) return <></>;
  return (
    <Camera
      style={{flex: 1}}
      device={device}
      isActive={true}
      frameProcessor={frameProcessor}
      frameProcessorFps={5}
    />
  );
};

i'm not sure that exactly why this works. But i will work around when i have some time

fundon commented 2 years ago

Same error:

libc++abi: terminating with uncaught exception of type facebook::jsi::JSError: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)

Error: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)
    at _f (native)
namnhagiletech commented 2 years ago

@whtjs how've you fixed it?. I still got this error

whtjs commented 2 years ago

@namnhagiletech did you try the solution?

namnh240795 commented 2 years ago

There no need to try the solution.

The correct way is import react-native-reanimated at index.js, remember to install pods for ios and config the babel file. It'll work

whtjs commented 2 years ago

@namnh240795 when i use with apollo-client@^3.5.4, i need to change metro.config.js to enable cjs extension

https://stackoverflow.com/questions/70338215/error-while-trying-to-resolve-module-apollo-client-react-native

alieska-listapad commented 2 years ago

Same issue for me. react-native-reanimated": "2.10.0 react-native": "0.70.0 vision-camera-code-scanner": "0.2.0

It crashes when I call scanBarcodes.

libc++abi: terminating with uncaught exception of type facebook::jsi::JSError: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)

Error: Exception in HostFunction: Javascript worklet error

Error: Javascript worklet error
    at _f (native)
    at _f (native)
whtjs commented 2 years ago

@aliaksei-niamkovich what platform are you crashing facing on ?? If iOS included what xcode version are you using?

alieska-listapad commented 2 years ago

@whtjs iOS, Version 14.0 (14A309)

whtjs commented 2 years ago

@aliaksei-niamkovich I also had same issue after upgrade to xcode 14, you can check this on react-native-vision-camera's issue

tl;dr try to

  1. downgrade xcode 13
  2. remove pods and reinstall
  3. clean & build
alieska-listapad commented 2 years ago

@whtjs Thanks, now It works!

ospfranco commented 2 years ago

Any news regarding this? According to the vision camera issue it's not an issue with vision camera, but rather with the Swift implementation of this (and other) plugin

tomekzaw commented 2 years ago

Hey all, react-native-reanimated maintainer here.

Exception in HostFunction: Javascript worklet error is a generic error message that shows up when some worklet throws an error (like undefined is not a function here). Reanimated catches all errors from worklets and passes them to the console or LogBox.

While the error is caused by other third-party library, we are currently improving the developer experience by presenting the full error message instead of only "Javascript worklet error". See the PR: https://github.com/software-mansion/react-native-reanimated/pull/3558

geobako commented 1 year ago

As per this issue for now you can do a patch so that you can build in Xcode 14

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb..b9e0a56 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h    
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h    
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \
whtjs commented 1 year ago

As per this issue for now you can do a patch so that you can build in Xcode 14

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb..b9e0a56 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h  
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h  
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Very Good Information!! Thanks 👍

mason-t3h commented 1 year ago

As per this issue for now you can do a patch so that you can build in Xcode 14

diff --git a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h
index a2ccdcb..b9e0a56 100644
--- a/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h  
+++ b/node_modules/react-native-vision-camera/ios/Frame Processor/FrameProcessorPlugin.h  
@@ -53,7 +53,7 @@ objc_name : NSObject<FrameProcessorPluginBase>
 @end                                                                                \
 @implementation objc_name (FrameProcessorPlugin)                                    \
                                                                                     \
-__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)()    \
++(void)load    \
 {                                                                                   \
   [FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) {    \
     return [objc_name callback:frame withArgs:args];                               \

Hi, I have applied this patch but still facing the same issue:(

ombogdanJoinToIt commented 1 year ago

same