vision-camera-code-scanner icon indicating copy to clipboard operation
vision-camera-code-scanner copied to clipboard

iOS - worklet error , Android - undefined error

Open whtjs opened this issue 3 years ago • 16 comments

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

whtjs avatar Jan 24 '22 03:01 whtjs

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)

fundon avatar Feb 20 '22 09:02 fundon

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

namnhagiletech avatar Jun 29 '22 10:06 namnhagiletech

@namnhagiletech did you try the solution?

whtjs avatar Jun 29 '22 11:06 whtjs

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

namnh240795 avatar Jun 30 '22 03:06 namnh240795

@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

whtjs avatar Jun 30 '22 03:06 whtjs

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)

alieska-listapad avatar Sep 21 '22 19:09 alieska-listapad

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

whtjs avatar Sep 21 '22 19:09 whtjs

@whtjs iOS, Version 14.0 (14A309)

alieska-listapad avatar Sep 21 '22 19:09 alieska-listapad

@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

whtjs avatar Sep 21 '22 19:09 whtjs

@whtjs Thanks, now It works!

alieska-listapad avatar Sep 21 '22 21:09 alieska-listapad

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

ospfranco avatar Sep 26 '22 10:09 ospfranco

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

tomekzaw avatar Sep 26 '22 12:09 tomekzaw

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];                               \

geobako avatar Oct 17 '22 10:10 geobako

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 👍

whtjs avatar Oct 18 '22 08:10 whtjs

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:(

mason-t3h avatar Dec 22 '22 03:12 mason-t3h

same

ombogdanJoinToIt avatar Jan 09 '23 12:01 ombogdanJoinToIt