angular - 未捕获的语法错误:无法在 Angular 和 Firebase 中的模块外部使用导入语句
问题描述
尝试连接 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' });
});
}
});
解决方案
注册服务人员时需要告诉它是一个模块
在 GitHub 上查看这个已解决的问题: https ://github.com/angular/angularfire/issues/3049#issuecomment-963388580
推荐阅读
- python - TypeError: unhashable type: 'numpy.ndarray' 将元组转换为集合
- spring - 使用外部 api 时 mime 类型无效
- c# - 如何在 Razor pages .Net 核心项目中访问 html 文件
- bash - bash exec 与不同的用户没有额外的过程
- php - 文件不在允许的路径内,但实际上是
- advanced-installer - 高级安装程序:查询结果未存储在属性中
- pine-script - 在 Pine 脚本中获取字符串长度
- kotlin - 是否可以对具有无参数且无结果的函数类型参数的函数进行断言?
- c - 如何在c中使矩形的两侧相等?
- python - Python re.search 正则表达式匹配