react-native-tiktok icon indicating copy to clipboard operation
react-native-tiktok copied to clipboard

Unhandled JS Exception: Invariant Violation: Cannot have a non-function arg after a function arg., js engine: hermes

Open haryelramalho opened this issue 10 months ago • 9 comments

I was using the old version that had auth, events, and init methods. But now, I need to upgrade to the new one because I need the Expo plugin, and I can’t open the SDK because the app crashes when it tries to.

This is the error:

*** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Invariant Violation: Cannot have a non-function arg after a function arg., js engine: hermes', reason: 'Unhandled JS Exception: Invariant Violation: Cannot have a non-function arg after a function arg., js engine: hermes, stack:
invariant@1045:25
nonPromiseMethodWrapper@2615:37
authorize@210636:27
anonymous@210465:39
anonymous@210512:77
onPress@218805:59
invokeFunc@197525:29
trailingEdge@197565:29
timerExpired@197554:31
anonymous@17051:49
_callTimer@17000:16
callTimers@17141:18
__callFunction@1294:37
anonymous@1133:29
__guard@1240:14
callFunctionReturnFlushedQueue@1132:20
'
*** First throw call stack:
(0x18fe7e5fc 0x18d3f9244 0x1005cf3b0 0x10063c4b4 0x10063ccdc 0x18fe80e34 0x18fe7fe7c 0x18fee3a38 0x100600b90 0x100602d00 0x100602954 0x102b3488c 0x102b36578 0x102b3e454 0x102b3f25c 0x102b4c6fc 0x102b4bd0c 0x21ac10680 0x21ac0e474)
libc++abi: terminating due to uncaught exception of type NSException

And here is the js code:

const handleGetTiktokData = useCallback(() => {
  authorize({
    redirectURI: <URL_HERE>,
    scopes: [Scopes.user.info.basic, Scopes.video.list],
    callback: (authCode, codeVerifier) => {
      // codeVerifier is returned only on Android
      console.log(authCode, codeVerifier);
    },
  });
}, []);

haryelramalho avatar Apr 03 '25 13:04 haryelramalho

Im also having the same issue, The reason seems to be passing "callback" as 2nd parameter. it should be final parameter

index.ts

export function authorize(props: Props): void {
  const { redirectURI, callback, scopes } = props;
  return Tiktok.authorize(redirectURI, callback, scopes);
}

@@Lg0gs Please share your thoughts, Thanks.

Ishara-Mee avatar Apr 27 '25 16:04 Ishara-Mee

@Ishara-Mee I'm sorry for not getting back to you sooner, sometimes I don't have much free time.. Are you migrating from v1?

Lg0gs avatar Apr 29 '25 06:04 Lg0gs

We have the same problem, and we've migrated from version 1.

humanzai avatar Apr 29 '25 13:04 humanzai

@Ishara-Mee I'm sorry for not getting back to you sooner, sometimes I don't have much free time.. Are you migrating from v1?

No, It is a fresh installation for RN 0.73.9

Ishara-Mee avatar Apr 29 '25 16:04 Ishara-Mee

Are you fix it

quochuy2405 avatar May 25 '25 06:05 quochuy2405

@quochuy2405 , I developed a native module

Ishara-Mee avatar May 25 '25 16:05 Ishara-Mee

@quochuy2405 please try this patch

diff --git a/node_modules/react-native-tiktok/.DS_Store b/node_modules/react-native-tiktok/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/react-native-tiktok/ios/Tiktok.mm b/node_modules/react-native-tiktok/ios/Tiktok.mm
index 1b3c789..8202d9c 100644
--- a/node_modules/react-native-tiktok/ios/Tiktok.mm
+++ b/node_modules/react-native-tiktok/ios/Tiktok.mm
@@ -5,8 +5,8 @@ @interface RCT_EXTERN_MODULE(Tiktok, RCTEventEmitter)
 
 RCT_EXTERN_METHOD(
                   authorize: (NSString)redirectURI
-                  callback: (RCTResponseSenderBlock)callback
                   scopes:(NSArray * _Nullable)scopes
+                  callback: (RCTResponseSenderBlock)callback
                   )
 
 + (BOOL)requiresMainQueueSetup
diff --git a/node_modules/react-native-tiktok/ios/Tiktok.swift b/node_modules/react-native-tiktok/ios/Tiktok.swift
index add9a0d..7342bdd 100644
--- a/node_modules/react-native-tiktok/ios/Tiktok.swift
+++ b/node_modules/react-native-tiktok/ios/Tiktok.swift
@@ -6,7 +6,7 @@ class Tiktok: RCTEventEmitter {
   let authRequest = TikTokAuthRequest(scopes: [], redirectURI: "")
 
   @objc
-  func authorize(_ redirectURI: String, callback: @escaping RCTResponseSenderBlock, scopes: [String]?) -> Void {
+  func authorize(_ redirectURI: String, scopes: [String]?, callback: @escaping RCTResponseSenderBlock) -> Void {
     DispatchQueue.main.async {
       self.authRequest.redirectURI = redirectURI
       self.authRequest.scopes = Set(scopes ?? ["user.info.basic"])
diff --git a/node_modules/react-native-tiktok/lib/commonjs/index.js b/node_modules/react-native-tiktok/lib/commonjs/index.js
index a8b792e..f03350b 100644
--- a/node_modules/react-native-tiktok/lib/commonjs/index.js
+++ b/node_modules/react-native-tiktok/lib/commonjs/index.js
@@ -31,6 +31,6 @@ function authorize(props) {
     callback,
     scopes
   } = props;
-  return Tiktok.authorize(redirectURI, callback, scopes);
+  return Tiktok.authorize(redirectURI, scopes, callback);
 }
 //# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/node_modules/react-native-tiktok/lib/module/index.js b/node_modules/react-native-tiktok/lib/module/index.js
index 0ebe798..052b924 100644
--- a/node_modules/react-native-tiktok/lib/module/index.js
+++ b/node_modules/react-native-tiktok/lib/module/index.js
@@ -26,6 +26,6 @@ export function authorize(props) {
     callback,
     scopes
   } = props;
-  return Tiktok.authorize(redirectURI, callback, scopes);
+  return Tiktok.authorize(redirectURI, scopes, callback);
 }
 //# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/node_modules/react-native-tiktok/src/index.tsx b/node_modules/react-native-tiktok/src/index.tsx
index bdefd47..7a7d49d 100644
--- a/node_modules/react-native-tiktok/src/index.tsx
+++ b/node_modules/react-native-tiktok/src/index.tsx
@@ -29,5 +29,5 @@ const Tiktok = NativeModules.Tiktok;
 
 export function authorize(props: Props): void {
   const { redirectURI, callback, scopes } = props;
-  return Tiktok.authorize(redirectURI, callback, scopes);
+  return Tiktok.authorize(redirectURI, scopes, callback);
 }

hoangdoanfinx avatar May 27 '25 10:05 hoangdoanfinx

I used patch-package to fix it;

react-native-tiktok+2.1.14.patch

AcaciusShun avatar Jun 10 '25 10:06 AcaciusShun

getting " com.facebook.react.bridge.ReadableNativeArray cannot be cast to java.lang.Double"

apcexchange avatar Jun 26 '25 20:06 apcexchange