My Service worker works well enough for the token to be generated on my localhost, but whenever I deploy it doesn't work. If it makes a difference, I've used the create-react-app buildpack, so I run npm run build and then firebase deploy to get my app up and running (with build as the root folder). I've checked, and the firebase-messaging-sw.js does exist on my deployed version. Here're the error message I receive in the console:
firebase-messaging-sw.js:2 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://www.gstatic.com/firebasejs/3.4.0/firebase-messaging.js' failed to load. at https://nearify-f2a4a.firebaseapp.com/firebase-messaging-sw.js:2:1 (anonymous) @ firebase-messaging-sw.js:2
A bad HTTP response code (404) was received when fetching the script.
firebase-messaging-sw.js:2 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://www.gstatic.com/firebasejs/3.4.0/firebase-messaging.js' failed to load. at https://nearify-f2a4a.firebaseapp.com/firebase-messaging-sw.js:2:1 (anonymous) @ firebase-messaging-sw.js:2 A bad HTTP response code (404) was received when fetching the script.
the issue was with the import scripts, we should instead be using '/_/' import scripts and not trying to use the 'https://' etc. You can find more here: https://firebase.google.com/docs/cloud-messaging/js/receive
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.