FirebaseError - messaging/failed-serviceworker-reg

2019-07-31 08:42发布

问题:

Okey here is the deal, I have asked a couple of firebase related question already in Stackoverflow, and even without any answers I managed to get firebase working, and received a bunch of notifications. I really don't know what I did to make it work, it was a combination of lots of things.

(Related issues posted earlier: How to include firebase cloud messaging into ReactJS project using webpack | Firebase FCM with ReactJS and Webpack not working: We are unable to register the default service worker)

Anyhow, now it is not working again. I tried to simplify some configurations etc. and I broke the service-worker.

Now when I am trying to register the default firebase service-worker, I get the following error. When I type localhost:8000/firebase-messsaging-sw.js into my address bar, the file opens up though.

The thing that mystifies me is that "window is not defined error" since I have no idea why it is giving that. When I open up the file where it is coming from, I get this line of code:

Notice that I have the firebase-messaging-sw.js file running as a worker there, and opening that file opens a bunch of code, so something is registered by firebase.

WHAT I AM ASKING IS: How do I get rid of these firebase/messaging cannot register the default service worker errors, and that window is not defined error, and get FCM running stable?

回答1:

I managed to solve my problem (again without any answers..). I needed to downgrade webpack-dev-server from 2.11.1 to 2.11.0! I am hoping that this might help someone else having this issue.