Home > front end >  Firebase addDoc error => admin:1 Uncaught (in promise) FirebaseError: Expected type 'Na'
Firebase addDoc error => admin:1 Uncaught (in promise) FirebaseError: Expected type 'Na'

Time:10-03

I am getting this error . I am succesfully adding my image to Storage and getting my URL but when I want to add document to my collection I am getting this error. I am implementing the code same way Firebase do here is the reference for addDoc => https://firebase.google.com/docs/firestore/manage-data/add-data#web-version-9_1

admin:1 Uncaught (in promise) FirebaseError: Expected type 'Na', but it was: a custom an object

uploadTask.on(
  "state_changed",
  (snapshot) => {
    setProgress((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
    console.log();
  },
  (error) => {
    console.log(error);
  },
  () => {
    // Get ImageURL
    getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => {
      setImgURL(downloadURL);
      // Add new collection document to FIREBASE
      addDoc(portfolioItemsCol, {
        img: downloadURL,
        title: title,
      })
        .then((docRef) => {
          console.log("Document succesfully Added");
        })
        .catch((err) => console.log(err));
    });
  }
);

Link to code : https://codesandbox.io/s/exciting-ace-ttbjqv?file=/src/App.js

CodePudding user response:

Avoid using both the regular and lite versions at the same time. Here you are using getFirestore() from firebase/firestore/lite but addDoc() from firebase/firestore. Try using the following import in App.js:

import { addDoc } from "firebase/firestore/lite" // <-- add /lite

Alternatively, import getFirestore() from regular SDK but that'll useful if you need to use real-time listeners later.

  • Related