简体   繁体   中英

Firebase FCM with ReactJS and Webpack not working: We are unable to register the default service worker

Related question with pretty much the same issue: Firebase FCM React project issue - firebase-messaging-sw.js wrong type?

Answers in this question or any other have not worked for me, below is a screenshot of the project tree with firebase-messaging-sw.js file in it, since adding it has been a occuring suggestion to fix this issue.

firebase-messaging-sw

I would like to know if I am just doing it wrong or why I am not able to register the sw for the firebase to use.

Original error from developer tools console: "Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script."

As an aswer to this issue, here is another post by me which I also managed to solve myself. FirebaseError - messaging/failed-serviceworker-registration

So basically using a very specific version of webpack-dev-server, adding a sw file that can have any name, and registering that file as a service worker for fireabse to use in my firebase messaging initialization file, I managed to get firebase cloud messaging working with webpack. The version of webpack-dev-server is 2.11.0.

Hope this helps anyone with this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM