[英]Cannot use import statement outside the module in firebase
I am using firebase to integrate chat and using the following code in firebase.messaging-sw.js but it is throwing the following errors.我正在使用 firebase 集成聊天并在 firebase.messaging-sw.js 中使用以下代码,但它会引发以下错误。
Code:代码:
import { getMessaging } from "firebase/messaging";
import { onBackgroundMessage } from "firebase/messaging/sw";
const messaging = getMessaging();
onBackgroundMessage(messaging, (payload) => {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};
self.registration.showNotification(notificationTitle,
notificationOptions);
});
In case if I use Import:如果我使用导入:
import { getMessaging } from "firebase/messaging";
Cannot use import statement outside of the module
In case of require:如有需要:
let { getMessaging }=require("firebase/messaging");
Require is undefined
I am using the combination of Laravel, Node and Javascript我正在使用 Laravel、Node 和 Javascript 的组合
import { getMessaging } from "firebase/messaging/sw";
This should be how you import getMessaging.这应该是您导入 getMessaging 的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.