javascript - ERROR Registration Error: [TypeError: this._firestore.native.documentSet is not a function (it is undefined)] - Sta

admin2025-04-28  2

I'm developing a user registration feature in a React Native app using Firebase Firestore to store user details. However, I keep encountering a TypeError during the Firestore document set operation.

Environment:

react-native": "0.76.5",
@react-native-firebase/app": "^21.6.2",
@react-native-firebase/firestore": "^21.6.2",

Testing Device/Emulator: [iOS and Android ]

I implemented user registration and data storage using Firestore in my React Native app. Here's what I expected and what I tried:

Expected: Successfully register a user and store their information (first name, last name, email, and registration timestamp) in Firestore.

Attempted: Used the Firestore set method to write user data after successful registration.

Code:

const handleRegister = async () => {
        if (validateInput()) {
            try {
                const userCredential = await registerUserWithEmail(email, password);
                console.log('User registered:', userCredential.user);
    
                const db = firestore();
                const userRef = db.collection('users').doc(userCredential.user.uid);
                console.log('Firestore Reference:', userRef);
    
                // Attempt to write to Firestore and log the process
                userRef.set({
                    firstName: firstName,
                    lastName: lastName,
                    email: email,
                    createdAt: firestore.FieldValue.serverTimestamp()
                })
                .then(() => {
                    console.log('User data set in Firestore');
                    Alert.alert('Success', 'Account Created Successfully');
                    navigation.navigate('Login');
                })
                .catch(error => {
                    console.error('Firestore set error:', error);
                    Alert.alert('Registration Failed', error.message);
                });
    
            } catch (error) {
                console.error('Registration Error:', error);
                Alert.alert('Registration Failed', `${error.message} [${error.code}]`);
            }
        }
    };

However, I keep encountering a TypeError when the set method is called, specifically complaining about documentSet not being a function. I expected the Firestore set operation to run without errors and store the user data.

Debugging Steps Taken:

Ensured the Firestore and Firebase SDKs are up-to-date. Checked Firestore permissions to ensure write access is enabled. Reviewed Firebase documentation to confirm usage of APIs. Added console logs to trace the values and confirm the presence of Firestore methods.

Error Message: [TypeError: this._firestore.native.documentSet is not a function (it is undefined)]

I'm developing a user registration feature in a React Native app using Firebase Firestore to store user details. However, I keep encountering a TypeError during the Firestore document set operation.

Environment:

react-native": "0.76.5",
@react-native-firebase/app": "^21.6.2",
@react-native-firebase/firestore": "^21.6.2",

Testing Device/Emulator: [iOS and Android ]

I implemented user registration and data storage using Firestore in my React Native app. Here's what I expected and what I tried:

Expected: Successfully register a user and store their information (first name, last name, email, and registration timestamp) in Firestore.

Attempted: Used the Firestore set method to write user data after successful registration.

Code:

const handleRegister = async () => {
        if (validateInput()) {
            try {
                const userCredential = await registerUserWithEmail(email, password);
                console.log('User registered:', userCredential.user);
    
                const db = firestore();
                const userRef = db.collection('users').doc(userCredential.user.uid);
                console.log('Firestore Reference:', userRef);
    
                // Attempt to write to Firestore and log the process
                userRef.set({
                    firstName: firstName,
                    lastName: lastName,
                    email: email,
                    createdAt: firestore.FieldValue.serverTimestamp()
                })
                .then(() => {
                    console.log('User data set in Firestore');
                    Alert.alert('Success', 'Account Created Successfully');
                    navigation.navigate('Login');
                })
                .catch(error => {
                    console.error('Firestore set error:', error);
                    Alert.alert('Registration Failed', error.message);
                });
    
            } catch (error) {
                console.error('Registration Error:', error);
                Alert.alert('Registration Failed', `${error.message} [${error.code}]`);
            }
        }
    };

However, I keep encountering a TypeError when the set method is called, specifically complaining about documentSet not being a function. I expected the Firestore set operation to run without errors and store the user data.

Debugging Steps Taken:

Ensured the Firestore and Firebase SDKs are up-to-date. Checked Firestore permissions to ensure write access is enabled. Reviewed Firebase documentation to confirm usage of APIs. Added console logs to trace the values and confirm the presence of Firestore methods.

Error Message: [TypeError: this._firestore.native.documentSet is not a function (it is undefined)]

Share Improve this question edited Jan 9 at 19:13 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges asked Jan 9 at 18:36 user29129991user29129991 1 1
  • If you are running RN with Expo, you might have run into the edge case encountered in invertase/react-native-firebase#8196. – samthecodingman Commented Jan 10 at 1:41
Add a comment  | 

1 Answer 1

Reset to default 0

The error looks to be in this part of your code:

// Attempt to write to Firestore and log the process
userRef.set({
    firstName: firstName,
    lastName: lastName,
    email: email,
    createdAt: firestore.FieldValue.serverTimestamp()
})

The error is letting you know that there is no set() method available on the Document object. Instead use the setDoc() like so:

  1. Add the setDoc method to your imports:
import { doc, setDoc } from "firebase/firestore";
  1. Replace the code mentioned above with this:
// Attempt to write to Firestore and log the process
await setDoc(userRef, {
    firstName: firstName,
    lastName: lastName,
    email: email,
    createdAt: firestore.FieldValue.serverTimestamp()
})
转载请注明原文地址:http://www.anycun.com/QandA/1745780260a91191.html