RCTBatchedBridge.m Error: Invalid data message - all must be length:%zd. React Native, iOS simulator

2.2k views Asked by At

I'm using react-native-oauth and getting this error (see red image at bottom) when trying to authorise. I've searched and found only this similar unanswered question. I looked into the source and found where the error is raised on line 954 and it seems it's because moduleIDs.count should equal methodIDs.count and paramsArrays.count :

  if (RCT_DEBUG && (moduleIDs.count != methodIDs.count || moduleIDs.count != paramsArrays.count)) {
RCTLogError(@"Invalid data message - all must be length: %zd", moduleIDs.count);

So, still in the source, I look for these objects and find them defined just above, on lines 943-945 and they are using RCTConvert, whose functions "...all accept a JSON value as input and map it to a native Objective-C type or class." - React's docs

So it seems like this is a transpiling and/or networking related error. But I have basically 0 knowledge on those fields and feel I've hit a barrier to investigating and wondered if anybody had any ideas on moving forward. Being new to React Native and never having done any Objective-C can't be helping me.

Also, here's my code generating the errors.

import OAuthManager from 'react-native-oauth';
import {
Alert
} from 'react-native'
var env = require('../environment.js')
const config =  {
  facebook: {
    client_id: env.getKey("FB_ID"),
    client_Secret: env.getKey("FB_SECRET")
  }
}
const manager = new OAuthManager('myAppName')
manager.configure(config);
exports.authWithFb = () => {
   manager.authorize('facebook')
     .then(resp => Alert.alert('response!' + resp))
     .catch(err => Alert.alert('error msg here: ' + err));
}

I am guessing this undefined error is related to the RCTBridge error but not sure. You can below see when I Alert the manager.authorize's caught error. TypeError: undefined is not an object (evaluating 'fn'):

enter image description herethis error

Edit:

When I try to Alert the config object, I get an error about not being able to stringify it's sub-object. enter image description here

When looking in console in chrome debugger, I get "Cannot read property 'configureProvider' of undefined" and configureProvider() is what react-native-oauth uses so it looks like the manager is not set up right so maybe I didn't link the library well. Have checked the linking worked.

Im digging into the errors a bit and it seems like a promise/callback related problem from NativeModules.OAuthManager. The error caught is: TypeError: Cannot read property 'authorize' of undefined. When I jump into the stack trace I find: enter image description here

Any help is much appreciated, thanks.

2

There are 2 answers

1
Shahen Hovhannisyan On

You'll get this error when you will send some wrong data into native side. For example if you should pass string but you passed an object.

Please console.log your config variable.

https://www.npmjs.com/package/react-native-oauth

I guess you're sent some wrong data into native side

0
Tam Borine On

So for me whatever was going wrong was a setup issue with react-native-oauth because everything has fixed itself since I've rolled back to a point where my code had no other dependencies (I also had Firestack installed) and set up from scratch again following react-native-oauth's docs. I realised that there was a step on iOS/XCode's side that I had missed out because when I originally tried I couldn't find the file so just skipped that step:

From react-native-oauth readme

Next, navigate to the neighboring "Build Phases" section of project settings, find the "Link Binary with Library" drop down, expand it, and click the "+" to add libOAuthManager.a to the list.

The errors I were getting were a few steps removed from this but I'm sure connected somehow. Lessons learnt: don't try to do too many things at once and don't skip required steps.