invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.64k stars 2.21k forks source link

[iOS] `Cannot call a class as a function` when await firestore().collection(...) #2864

Closed michaelkowalski closed 4 years ago

michaelkowalski commented 4 years ago

I'm using the newest firebase and firestore in my new project:

    "@react-native-firebase/firestore": "^6.0.3",
    "react": "16.9.0",
    "react-native": "0.61.4",

Installed like this https://invertase.io/oss/react-native-firebase/quick-start/new-project and like this https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start.

I'm importing firestore just like in the examples here: https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data. My code:


  const save = useCallback(async () => {
    await firestore()
      .collection('foo')
      .add({ bar: 'baz' )
  }, [])

And I'm getting this warning:

TypeError: Cannot call a class as a function
TypeError: Cannot call a class as a function
    at _classCallCheck (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:2808:13)
    at Function.FirestoreGeoPoint [as GeoPoint] (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:126651:36)
    at _callee$ (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:121658:46)
    at tryCatch (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29304:19)
    at Generator.invoke [as _invoke] (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29479:24)
    at Generator.prototype.<computed> [as next] (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29347:23)
    at tryCatch (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29304:19)
    at invoke (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29380:22)
    at http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:29410:13
    at tryCallTwo (http://192.168.8.110:8081/index.bundle?platform=ios&dev=true&minify=false:3267:7)

Am I doing something wrong? I removed and installed node_modules, installed the pods, rebuild the project and nothing...

Salakar commented 4 years ago

Hey

Are you able to provide a full example of the document you're trying to add to the collection, the stack trace seems to indicate you're doing something with GeoPoint?

michaelkowalski commented 4 years ago

@Salakar many thanks! I didn't notice the GeoPoint mentioned in the stack trace... 🤦🏻‍♂️ That's right, that's the issue. My full code was the following:

    await firestore()
      .collection('data')
      .add({
        name,
        photoDescription,
        comment,
        what,
        location: firestore.GeoPoint(location.latitude, location.longitude),
        accuracy: location.accuracy
      })
  }, [name, photoDescription, comment, what, location])

EDIT

For anyone coming here with the same issue, that's the proper method of doing this:

import firestore, { firebase } from '@react-native-firebase/firestore'

    await firestore()
      .collection('data')
      .add({
        name,
        photoDescription,
        comment,
        what,
        location: new firebase.firestore.GeoPoint(location.latitude, location.longitude),
        accuracy: location.accuracy
      })