简体   繁体   中英

Unable to import Firebase JS SDK with React Native Expo

In my React Native app, I am trying to use the Firebase JS SDK with Expo as mentioned in this guide , although after installing the dependencies via expo install firebase , I am unable to import modules from firebase/auth . Calling the respective methods like getAuth() results in the following error:

TypeError: (0, _auth.getAuth) is not a function. (In '(0, _auth.getAuth)()', '(0, _auth.getAuth)' is undefined)

I am also unable to import modules from firebase/database , firebase/firestore etc.

My project is set up using Typescript, but I also experienced this problem with a JS-only project.

I am able to import firebase from firebase/app , but not the respective modules: 在此处输入图片说明

edit: I am using getAuth() and the other methods in the following context:

React.useEffect(() => {

 if (response?.type === "success") {
  const { id_token } = response.params;

  const auth = getAuth();      
  const provider = new GoogleAuthProvider();
  const credential = provider.credential(id_token);
  signInWithCredential(auth, credential);
 }
}, [response]);

I am using Firebase 8.2.3.

The import syntax you're using is for Firebase SDK version 9 and later. For version 8 and below, use:

import firebase from 'firebase/app';
import 'firebase/auth';
...

And then use the v8 syntax as shown here .

不幸的是,最新的 expo sdk 与 firebase9 不兼容,如果您使用此版本的 firebase,您会看到奇怪的错误音调,请使用 firebase 版本 8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM