import { initializeApp } from 'firebase/app';
import { getAuth, signInWithPhoneNumber, PhoneAuthProvider,signInWithCredential } from 'firebase/auth';
import { getMessaging } from 'firebase/messaging';
const firebaseConfig = {
This is config
};
const app = initializeApp(firebaseConfig);
const messaging = getMessaging(app); // problem is on this line
const auth = getAuth(app);
export { auth, signInWithPhoneNumber, PhoneAuthProvider,signInWithCredential,messaging};`
它显示此错误 TypeError:无法读取未定义的属性“addEventListener”
以下是排查和解决问题的方法:
import { initializeApp } from 'firebase/app';
import { getAuth, signInWithPhoneNumber, PhoneAuthProvider, signInWithCredential } from 'firebase/auth';
import { getMessaging, isSupported } from 'firebase/messaging';
const firebaseConfig = {
// Your Firebase config here
};
const app = initializeApp(firebaseConfig);
let messaging;
isSupported().then((supported) => {
if (supported) {
messaging = getMessaging(app);
} else {
console.warn('Firebase Messaging is not supported in this environment.');
}
});
const auth = getAuth(app);
export { auth, signInWithPhoneNumber, PhoneAuthProvider, signInWithCredential, messaging };