FirebaseError: messaging/failed-serviceworker-registration
Hi,
I got below error. Please help
Requesting permission... /quicks...saging/ (line 218) Notification permission granted. /quicks...saging/ (line 222) An error occurred while retrieving token. FirebaseError: Messaging: We are unable to register the default service worker. ServiceWorker script at http://localhost:8080/firebase-messaging-sw.js for scope http://localhost:8080/firebase-cloud-messaging-push-scope encountered an error during installation. (messaging/failed-serviceworker-registration). { code="messaging/failed-serviceworker-registration", message="Messaging: We are unable...ceworker-registration).", name="FirebaseError", more...}
Thanks and Regards, Ben
If you open a new tab for and add the following URL, does anything show up?
http://localhost:8080/firebase-messaging-sw.js
i've inlcuded firebase-messaging-sw.js but the error it's equal to past . In principal script when include firebse-sw.file ?
you shouldn't be including the service worker file anywhere. The SDK will register it when needed.
That error generally means that the file can't be found at the root of the origin.
So if you enter in http://localhost:8080/firebase-messaging-sw.js into a browser, does it return the file or does it show an error page?
Its Return JS file content not giving error!! I had Put all the content on my server still i get these error ? Does anyone have found solution?
If you can provide an example repo or site that is showing it not working that would be helpful.
http://localhost:8080/firebase-messaging-sw.js. I am getting page not found error for this. Can you help?
@vaijan1990 are you starting your server at the root or this repository or are you starting you server inside the messaging/ folder? It needs to be the latter.
Yes. Thanks. It works now.
@gauntface im getting the same error.. whn i navigate to localhost:8080/firebase-messaging-sw.js is not found. and i placed it in root of my project.
@emjimadhu just make it so that your server setup allows '
Without more information - extremely difficult to help you.
@gauntface ok sorry for that.. here is the detail.. im using VueJS as my front end and my folder structure is like below..
webApp
..| - build
..| - config
..| - node_modules
..|| - src
........|| - assets
........|| - components
........|| - pages
........|| - app.vue
........|| - main.js
..| - index.html
..| - firebase-messaging-sw.js <= here is my actual service worker
so when i run my application, i get log stating that my service worker is not found.. in this folder structure where i have to place the service worker?
thank you in advance.

@emjimadhu This is how you should debug this:
- Start your server
- Load you web page in a browser
- In your browser change your url to access the firebase-messaging-sw.js file (i.e. http://localhost:8080/firebase-messaging-sw.js - replacing the port etc).
- Notice that the file is not being served (I imagine your server redirects to index.html since it's a single page app).
- Debug how you would serve that file from the expect location. In this case, I imagine you need to put it in that static directory, or perhaps there is a way to configure your server not to redirect your URL.
Hi, I'm using the vuejs webpack template and am having the same problem. I put the firebase-messaging-sw.js into do the dist folder and got it uploaded to firebase hosting as it worked. But in the dev environment it does not work. I guess it's because of the file not getting served in the local web server and that due the the complex setup with webpack and hot reloading and all.
Hello, I am trying to use push-notification on Django Python website... I have created App on FCM, followed the instruction... I used JavaScript CDN... Now I am getting the following error while trying push-notification in my project
GET http://localhost:8080/firebase-messaging-sw.js net::ERR_INVALID_RESPONSE
An error occurred while retrieving token.
e {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…t. (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP res…code (404) was received when fetching the script."}
firebase-messaging-sw.js this file and .html file both are in same directory
When I tried http://localhost:8080/firebase-messaging-sw.js this in url
I got Page not found (404)
Please can help me to figure out... What I have done wrong....?
Thank You In Advance...
@shreejayp95 you must fix the issue 'http://localhost:8080/firebase-messaging-sw.js' OR use the useServiceWorker() function to pass in a custom service worker registration: https://firebase.google.com/docs/reference/js/firebase.messaging.Messaging#useServiceWorker
If you are using Vue.js and Webpack and have problems in dev mode, just try to firebase serve.
this worked for me
Hi All,
Where do i get this file from? I get this after npm install on new project.

this file is not available in my project folder.
Thank you.
@chanakyanet you need to create the file in your project.
Example: https://github.com/firebase/quickstart-js/blob/master/messaging/firebase-messaging-sw.js
@sharkaev , could you please elaborate on how you solved it? I am facing similar situation.
Stop firebase-messaging-sw.js service worker. Maybe you activated it on another project.