Setup errors with Expo

Hi all !

I’ve seen that the CometChat SDK for react native has issues with Expo, regarding the @cometchat-pro/react-native-calls module (Calling), but I just need to implement messages at the moment.

I am using a TS expo stack (~42.0.1), and the @cometchat-pro/react-native-chat module (v3.0.0). When I try to login, I get the following error :

const settings = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(this._APP_REGION).build();
 CometChat.init(this._APP_ID, settings)
.then(_ => {
  CometChat.login(cometChatId, this._APP_KEY)
  .then(_ => console.log("Logged in"))
  .catch(_=> console.log("error", _)) 
  // Shows : {name: "TypeError", message: "Cannot read property 'get' of undefined"}
})

Although if I downgrade @cometchat-pro/react-native-chat to v2.0.7 (just to remove the integration react-native-calls entierly), the message indicates :

const settings = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(this._APP_REGION).build();
 CometChat.init(this._APP_ID, settings)
.then(_ => {
  CometChat.login(cometChatId, this._APP_KEY)
  .then(_ => console.log("Logged in"))
  .catch(_=> console.log("error", _)) 
  // Shows : {code: "-1" details: {} message: "please initialize the cometchat before using login method", name: "COMETCHAT_INITIALIZATION_NOT_DONE"}
})

I’m not sure if those are two different issues, or if in the first case initialization failed as well and the error message would not be as explicit as in v2.0.7.

Do you guys have any idea of what I’m doing wrong ?

Hello @AidenPearce,

Can you please let us know if you have installed the @react-native-async-storage/async-storage package as mentioned in the documentation?

Warm Regards,

CometChat Pro
Mayur Bhandari

Hey @mayur.bhandari ! Thanks for your quick reply !

I do have @react-native-async-storage/async-storage installed ! :smiley:

Hello @AidenPearce,

I created a new expo TS project and installed the following two packages,

"@cometchat-pro/react-native-chat": "^3.0.0",
"@react-native-async-storage/async-storage": "^1.15.7",

Added the following function in the App.tsx file,

const init = () => {
  let appSettings = new CometChat.AppSettingsBuilder().setRegion(COMETCHAT_CONSTANTS.REGION).subscribePresenceForAllUsers().build();
  CometChat.init(COMETCHAT_CONSTANTS.APP_ID, appSettings).then(
    initialized => {
      console.log("Init successful.", initialized);
      CometChat.login(COMETCHAT_CONSTANTS.UID, COMETCHAT_CONSTANTS.AUTH_KEY).then(
        user => {
          console.log("User logged in successfully.", user);
        }, error => {
          console.log("Some error occurred while login.", error);
        }
      )
    }, error => {
      console.log("Some error occurred while init.", error);
    }
  )
}

And I have added a Touchable Opacity on a text which calls this function,

<TouchableOpacity onPress={()=>{init()}}> 
    <Text> Initialize CometChat </Text> 
</TouchableOpacity>

And everything seems to be working fine on my end.

Warm Regards,

CometChat Pro
Mayur Bhandari

Thank you for your answer @mayur.bhandari !

I updated my packages to the same versions you did, and weirdly enough your code does not work on my end, I keep getting :

A little investigation in the debugger shows that the issues are in fact related to the localStorage :

Although I just checked on mobile, and have no issue !

Hello @AidenPearce,

Can you please let me know on which device are you facing this issue? I created a new expo app and with the above setup, everything seems to be working fine at my end.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hello @mayur.bhandari, the issue is showing up only on the web version (so only on my computer), I tried on my Android device and had no problem !

I use async storage elsewhere in my code and it seems to be working fine in the browser too ! :confused: