当我在服务器上部署我的应用程序时出现此错误,但它在 localhost 上运行良好,请问我该如何解决?我的公共目录文件中还有用于后台通知的 firebase-messaging-sw.js文件,但错误必须在 firebase.js 文件中,因为当我删除它时,错误已消除。
这是我的Firebase.js文件代码
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getMessaging ,getToken,onMessage,isSupported} from "firebase/messaging";
import { getAnalytics } from "firebase/analytics";
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
const app=initializeApp(firebaseConfig);
getAnalytics(app);
// we need to check if messaging is supported by the browser
let messaging ;
if(isSupported()) {
messaging = getMessaging();
}
export const requestForToken = () => {
return getToken(messaging, { vapidKey: "" })
.then((currentToken) =>{
if (currentToken) {
localStorage.setItem("RToken", currentToken);
console.log('current token for client: ', currentToken);
// Perform any other necessary action with the token
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
}
})
.catch((err) =>{
console.log('An error occurred while retrieving token. ', err);
});
};
export const onMessageListener = () =>
new Promise((resolve) =>{
onMessage(messaging, (payload) => {
// console.log("payload", payload)
resolve(payload);enter code here
});
});