Google cloud firestore FirebaseError::我们无法注册默认的服务工作者

Google cloud firestore FirebaseError::我们无法注册默认的服务工作者,google-cloud-firestore,push-notification,firebase-cloud-messaging,Google Cloud Firestore,Push Notification,Firebase Cloud Messaging,FirebaseError:消息传递:我们无法注册默认的服务工作者。未能为作用域()注册ServiceWorkerhttp://127.0.0.1:8000/firebase-云消息推送范围)和脚本('http://127.0.0.1:8000/firebase-消息sw.js'):获取脚本时收到错误的HTTP响应代码(404)。(消息/服务人员注册失败)。 PS:我在根文件夹中有firebase-messaging-sw.js(即/public) firebase messaging.js /

FirebaseError:消息传递:我们无法注册默认的服务工作者。未能为作用域()注册ServiceWorkerhttp://127.0.0.1:8000/firebase-云消息推送范围)和脚本('http://127.0.0.1:8000/firebase-消息sw.js'):获取脚本时收到错误的HTTP响应代码(404)。(消息/服务人员注册失败)。

PS:我在根文件夹中有firebase-messaging-sw.js(即/public)

firebase messaging.js

/*
Give the service worker access to Firebase Messaging.
Note that you can only use Firebase Messaging here, other Firebase libraries are not available in the service worker.
*/
importScripts('https://www.gstatic.com/firebasejs/7.23.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.23.0/firebase-messaging.js');

/*
Initialize the Firebase app in the service worker by passing in the messagingSenderId.
* New configuration for app@pulseservice.com
*/
firebase.initializeApp({            
        apiKey: "XXXXXXXXXXXXXX",
        authDomain: "XXXXXXXXXX.firebaseapp.com",
        projectId: "XXXXXXXXXX",
        storageBucket: "XXXXXXXXXX.appspot.com",
        messagingSenderId: "XXXXXXXXXXXX",
        appId: "XXXXXXXXXXXXXXX"
        });

/*
Retrieve an instance of Firebase Messaging so that it can handle background messages.
*/
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(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: "/itwonders-web-logo.png",
    };

    return self.registration.showNotification(
        notificationTitle,
        notificationOptions,
    );
});

当您尝试访问
http://127.0.0.1:8000/firebase-消息sw.js
?你是下载了.js还是下载了
404
(如消息所示)?如果是404,则说明您的项目配置方式存在问题。您需要提供更多信息:所使用的技术、HTTP服务器是什么等。在访问时,我获取文件的代码,但如果运行它,将在浏览器的“开发人员工具>>网络”选项卡中返回错误404,请查看哪个网络请求返回404。最好确切地知道浏览器认为它无法重新访问的URL是什么,比如说
加载资源失败:服务器以404(未找到)的状态响应
。我只在根文件夹中添加了
firebase messaging sw.js
,这是LaravelI think
https://stackoverflow.com/questions/59304861/firebase-messaging-js-not-found-laravel
是同一个问题,但我在答案中没有理解。(添加了firebase messaging.js的代码)