[英]Uncaught SyntaxError: Cannot use import statement outside a module in Angular & Firebase
I got this error in Angular when try to connect firebase push notification setting.尝试连接 Firebase 推送通知设置时,我在 Angular 中收到此错误。
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.0/firebase-app.js';
import { getMessaging, isSupported, onBackgroundMessage } from 'https://www.gstatic.com/firebasejs/9.1.0/firebase-messaging-sw.js';
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
const firebaseApp = initializeApp({
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
isSupported().then(isSupported => {
if (isSupported) {
const messaging = getMessaging(app);
onBackgroundMessage(messaging, ({ notification: { title, body, image } }) => {
self.registration.showNotification(title, { body, icon: image || '/assets/icons/icon-72x72.png' });
});
}
});
You need to tell it it's a module when you register a service worker注册服务人员时需要告诉它是一个模块
See this resolved issue on GitHub: https://github.com/angular/angularfire/issues/3049#issuecomment-963388580在 GitHub 上查看这个已解决的问题: https : //github.com/angular/angularfire/issues/3049#issuecomment-963388580
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.