DEV Community

Discussion on: The easiest way to extend or customize Create React App service worker without ejecting

Collapse
 
sjbuysse profile image
sjbuysse

Thanks for the last answer, one more comment that I needed to make it work for me in production as well.
Firebase is expecting a firebase-messaging-sw.js file to function as a service worker, but you are actually appending your firebase sw to the CRA serviceworker.js in your production build.
So you will have to let firebase messaging know that the serviceworker was registered else where by passing your serviceworker registration to the getToken() method when you call it.

messaging.getToken({serviceWorkerRegistration})
Enter fullscreen mode Exit fullscreen mode
Collapse
 
m3h0w profile image
Michał Gacka

Interesting. I wonder how I had it working then without passing that in (some kind of version discrepancy maybe?). Thanks for pointing it out! I'll include it in the post.