Mau*_*ino 4 firebase angularfire ionic-framework google-cloud-functions angular
所以我通过 AngularFire 调用 firebase 函数,如下所示:
const response = await this.aFunctions.httpsCallable<void, ResponseType>('funcName')().toPromise();
Run Code Online (Sandbox Code Playgroud)
这在部署到 firebase(托管)时有效,但在本地环境中(使用ionic serve),它会引发此错误:
ERROR Error: Uncaught (in promise): FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
Run Code Online (Sandbox Code Playgroud)
我在这个项目中没有以任何方式使用 FCM。你知道为什么会这样吗?
小智 5
好的,我通过解决整个应用程序中 Firebase 的导入问题来修复此问题。
// 此导入加载 firebase 命名空间及其所有类型信息。
import firebase from 'firebase/app';
// 这些导入将各个服务加载到 firebase 命名空间中。
import 'firebase/auth';
import 'firebase/database';
我能够删除 firebase-messaging-sw.js 文件,并且所有 onCall 函数都正常工作。
我以前混合过:
import firebase from 'firebase;
import * as firebase from 'firebase'
标准化一切以从“firebase/app”导入 firebase + 您需要的后续包
import 'firebase/functions'
现在一切正常了。
就我而言,我通过注释掉messagesSenderId 解决了这个问题。
firebase
: {
apiKey: 'XXXXX',
authDomain: 'XXXXX',
databaseURL: 'XXXXX',
projectId: 'XXXXX',
storageBucket: 'XXXXX',
// messagesSenderId
: 'XXXXX', <== 注释掉这个
appId: ' XXXXX'
}
我的情况有点不同和奇怪。我需要将一个 Angular 项目部署到 Firebase 托管。
代码?
const ob = this.functions.httpsCallable('api-name')({});
ob.subscribe((data)=>{//在这里做点什么});
错误:
FirebaseError:消息:我们无法注册默认的服务工作者......
环境:
本地:好的
firebase 托管默认域(projectName.web.app):错误
firebase 托管默认域(projectName.firebaseapp.com):好的
我不知道原因,但希望它可以帮助您和其他遇到类似问题的人。
| 归档时间: |
|
| 查看次数: |
310 次 |
| 最近记录: |