问题
Trying to add the Firebase script in my html, after initializing Firebase app with firebase.initializeApp(config);
.
So then I have this :
<script>
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button',
{
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
}
});
</script>
Which provides the error :
firebase.auth.RecaptchaVerifier is not a constructor error
- How to solve this error (found similar questions without a direct answer)
- How to proceed from here with the full flow ?
EDIT:
I have this in the beginning of the html :
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
I am initializing the app with :
<script>
var config = {
apiKey: "AIzaSxxxxxxxxxxxxxxxZQ14",
authDomain: "xxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxx.firebaseio.com",
projectId: "xxxxxx",
storageBucket: "xxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxx"
};
firebase.initializeApp(config);
const db = firebase.firestore();
db.settings({timestampsInSnapshots:true});
</script>
and those are the only things relate to Firebase I have in this file.
回答1:
Solved by changing version of the imported files with : (thanks a lot Frank)
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-functions.js"></script>
来源:https://stackoverflow.com/questions/55272773/firebase-auth-recaptchaverifier-is-not-a-constructor-error